Compare commits

..

No commits in common. "9829d40ee9a7deb22abc64e51b4aae7c651eb326" and "387036a958a4814a9d086a567da67190b53a1f71" have entirely different histories.

3 changed files with 4 additions and 13 deletions

View file

@ -3,17 +3,9 @@ import { db, schema } from "$lib/server/db";
const { precios } = schema;
import { sql } from "drizzle-orm";
let cache: null | { key: Date; data: { precios: Precios } } = null;
let cache: null | { key: Date; data: PageData } = null;
type Precios = {
ean: string;
name: string | null;
imageUrl: string | null;
}[];
export const load: PageServerLoad = async ({
params,
}): Promise<{ precios: Precios }> => {
export const load: PageServerLoad = async ({ params }) => {
if (cache && +new Date() < +cache.key + 1000 * 60 * 10) {
return cache.data;
}

View file

@ -13,7 +13,7 @@ export const load: PageServerLoad = async ({ params }) => {
const res = await q;
if (res.length === 0) return error(404, "Not Found");
const meta = res.findLast((p) => p.name);
const meta = res.find((p) => p.name);
return { precios: res, meta };
};

View file

@ -10,8 +10,7 @@ export const load: PageServerLoad = async ({ url }) => {
const sqlQuery = sql`select p.ean, p.name, p.image_url as imageUrl from precios_fts f
join precios p on p.ean = f.ean
where f.name match ${`"${query}"`}
group by p.ean
having max(p.fetched_at);`;
group by p.ean;`;
results = db.all(sqlQuery);
}