Compare commits

..

4 commits

Author SHA1 Message Date
9829d40ee9 chore: limpiar 2024-01-04 22:52:53 -03:00
26cb7b80e3 siempre conseguir ultima entry para busqueda 2024-01-04 22:50:44 -03:00
a1faa4f73c conseguir ultima imagen y nombre para pagina 2024-01-04 22:47:57 -03:00
930d1b109d sitio: corregir types 2024-01-04 22:33:36 -03:00
3 changed files with 13 additions and 4 deletions

View file

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

View file

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

View file

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