mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-22 14:16:19 +00:00
Compare commits
4 commits
387036a958
...
9829d40ee9
Author | SHA1 | Date | |
---|---|---|---|
9829d40ee9 | |||
26cb7b80e3 | |||
a1faa4f73c | |||
930d1b109d |
3 changed files with 13 additions and 4 deletions
|
@ -3,9 +3,17 @@ import { db, schema } from "$lib/server/db";
|
|||
const { precios } = schema;
|
||||
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) {
|
||||
return cache.data;
|
||||
}
|
||||
|
|
|
@ -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.find((p) => p.name);
|
||||
const meta = res.findLast((p) => p.name);
|
||||
|
||||
return { precios: res, meta };
|
||||
};
|
||||
|
|
|
@ -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
|
||||
join precios p on p.ean = f.ean
|
||||
where f.name match ${`"${query}"`}
|
||||
group by p.ean;`;
|
||||
group by p.ean
|
||||
having max(p.fetched_at);`;
|
||||
results = db.all(sqlQuery);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue