mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-26 11:36:20 +00:00
cachear home por 10 min
tarda mucho hacer la query random
This commit is contained in:
parent
0dd725aafd
commit
387036a958
1 changed files with 9 additions and 2 deletions
|
@ -1,9 +1,14 @@
|
||||||
import type { PageServerLoad } from "./$types";
|
import type { PageData, PageServerLoad } from "./$types";
|
||||||
import { db, schema } from "$lib/server/db";
|
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;
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params }) => {
|
export const load: PageServerLoad = async ({ params }) => {
|
||||||
|
if (cache && +new Date() < +cache.key + 1000 * 60 * 10) {
|
||||||
|
return cache.data;
|
||||||
|
}
|
||||||
const q = db
|
const q = db
|
||||||
.select({
|
.select({
|
||||||
ean: precios.ean,
|
ean: precios.ean,
|
||||||
|
@ -16,5 +21,7 @@ export const load: PageServerLoad = async ({ params }) => {
|
||||||
.orderBy(sql`random()`)
|
.orderBy(sql`random()`)
|
||||||
.limit(150);
|
.limit(150);
|
||||||
const res = await q;
|
const res = await q;
|
||||||
return { precios: res };
|
const data = { precios: res };
|
||||||
|
cache = { key: new Date(), data };
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue