This commit is contained in:
Cat /dev/Nulo 2024-09-14 18:12:47 -03:00
parent 4b2c360e17
commit 1f9daaa016
3 changed files with 15 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import { sql } from '$lib/server/db'; import { sql } from '$lib/server/db';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async () => { export const load: PageServerLoad = async ({ setHeaders }) => {
// https://www.cybertec-postgresql.com/en/postgresql-count-made-fast/ // https://www.cybertec-postgresql.com/en/postgresql-count-made-fast/
const count = await sql` const count = await sql`
SELECT reltuples::bigint SELECT reltuples::bigint
@ -9,6 +9,10 @@ export const load: PageServerLoad = async () => {
WHERE relname = 'precios'; WHERE relname = 'precios';
`; `;
setHeaders({
'Cache-Control': 'public, max-age=600'
});
return { return {
count: count[0].reltuples count: count[0].reltuples
}; };

View file

@ -2,7 +2,7 @@ import { db } from '$lib/server/db';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import { datasets, precios, sucursales } from '$lib/server/db/schema'; import { datasets, precios, sucursales } from '$lib/server/db/schema';
import { and, eq, sql } from 'drizzle-orm'; import { and, eq, sql } from 'drizzle-orm';
export const load: PageServerLoad = async ({ params }) => { export const load: PageServerLoad = async ({ params, setHeaders }) => {
const id = BigInt(params.id); const id = BigInt(params.id);
const preciosRes = await db const preciosRes = await db
.select({ .select({
@ -47,6 +47,10 @@ ORDER BY d1.id_comercio)
) )
.leftJoin(datasets, eq(datasets.id, precios.id_dataset)); .leftJoin(datasets, eq(datasets.id, precios.id_dataset));
setHeaders({
'Cache-Control': 'public, max-age=600'
});
// const precios = await sql< // const precios = await sql<
// { // {
// productos_precio_lista: number; // productos_precio_lista: number;

View file

@ -2,7 +2,7 @@ import { db } from '$lib/server/db';
import { sql } from 'drizzle-orm'; import { sql } from 'drizzle-orm';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params }) => { export const load: PageServerLoad = async ({ params, setHeaders }) => {
// const latestDatasetsSq = db.$with('latest_datasets').as( // const latestDatasetsSq = db.$with('latest_datasets').as(
// db.select({ // db.select({
// id: datasets.id, // id: datasets.id,
@ -75,6 +75,10 @@ WHERE p.id_producto = index.id_producto) as in_datasets_count
}> }>
); );
setHeaders({
'Cache-Control': 'public, max-age=600'
});
// 'latest_datasets', // 'latest_datasets',
// sql` // sql`
// WITH latest_datasets AS ( // WITH latest_datasets AS (