mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-22 22:26:19 +00:00
Compare commits
No commits in common. "d685ef8f758c45d31f8addf2aa6758c0014a0521" and "ca71dba59c23050c43a25c294257262a3b3fb462" have entirely different histories.
d685ef8f75
...
ca71dba59c
6 changed files with 9 additions and 52 deletions
3
.github/workflows/sepa-precios-archiver.yml
vendored
3
.github/workflows/sepa-precios-archiver.yml
vendored
|
@ -28,9 +28,6 @@ jobs:
|
||||||
B2_BUCKET_KEY_ID: ${{ secrets.B2_BUCKET_KEY_ID }}
|
B2_BUCKET_KEY_ID: ${{ secrets.B2_BUCKET_KEY_ID }}
|
||||||
B2_BUCKET_KEY: ${{ secrets.B2_BUCKET_KEY }}
|
B2_BUCKET_KEY: ${{ secrets.B2_BUCKET_KEY }}
|
||||||
run: |
|
run: |
|
||||||
# usar un servidor especifico porque parece que a veces
|
|
||||||
# bloquean el acceso desde afuera del país
|
|
||||||
sudo echo "190.2.53.185 datos.produccion.gob.ar" | sudo tee -a /etc/hosts
|
|
||||||
cd sepa
|
cd sepa
|
||||||
bun install --frozen-lockfile
|
bun install --frozen-lockfile
|
||||||
bun archiver.ts
|
bun archiver.ts
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# use the official Bun image
|
# use the official Bun image
|
||||||
# see all versions at https://hub.docker.com/r/oven/bun/tags
|
# see all versions at https://hub.docker.com/r/oven/bun/tags
|
||||||
FROM oven/bun:1.1 as base
|
FROM oven/bun:1.1 as base
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
@ -29,12 +28,10 @@ COPY db/schema.ts sitio2/src/lib/server/db/schema.ts
|
||||||
RUN cd sitio2 && bun install --frozen-lockfile
|
RUN cd sitio2 && bun install --frozen-lockfile
|
||||||
|
|
||||||
ARG DATABASE_URL
|
ARG DATABASE_URL
|
||||||
ARG SENTRY_AUTH_TOKEN
|
|
||||||
|
|
||||||
# [optional] tests & build
|
# [optional] tests & build
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV DATABASE_URL=$DATABASE_URL
|
ENV DATABASE_URL=$DATABASE_URL
|
||||||
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
|
|
||||||
|
|
||||||
# RUN bun test
|
# RUN bun test
|
||||||
RUN cd sitio2 && env DATABASE_URL="postgres://user:password@host:5432/db-name" bun run build
|
RUN cd sitio2 && env DATABASE_URL="postgres://user:password@host:5432/db-name" bun run build
|
||||||
|
|
BIN
sepa/bun.lockb
BIN
sepa/bun.lockb
Binary file not shown.
|
@ -1,29 +1,13 @@
|
||||||
import { sql } from '$lib/server/db';
|
import { sql } from '$lib/server/db';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import * as Sentry from '@sentry/sveltekit';
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ setHeaders }) => {
|
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 q = sql`
|
const count = await sql`
|
||||||
SELECT reltuples::bigint
|
SELECT reltuples::bigint
|
||||||
FROM pg_catalog.pg_class
|
FROM pg_catalog.pg_class
|
||||||
WHERE relname = 'precios';
|
WHERE relname = 'precios';
|
||||||
`;
|
`;
|
||||||
// https://github.com/getsentry/sentry-javascript/discussions/8117#discussioncomment-7623605
|
|
||||||
|
|
||||||
const count = await Sentry.startSpan(
|
|
||||||
{
|
|
||||||
op: 'db.query',
|
|
||||||
name: ` SELECT reltuples::bigint
|
|
||||||
FROM pg_catalog.pg_class
|
|
||||||
WHERE relname = 'precios';`,
|
|
||||||
data: { 'db.system': 'postgresql' }
|
|
||||||
// these properties are important if you want to utilize Queries Performance
|
|
||||||
// read more: https://docs.sentry.io/product/performance/queries/#span-eligibility
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
} as any,
|
|
||||||
async () => await q
|
|
||||||
);
|
|
||||||
|
|
||||||
setHeaders({
|
setHeaders({
|
||||||
'Cache-Control': 'public, max-age=600'
|
'Cache-Control': 'public, max-age=600'
|
||||||
|
|
|
@ -3,10 +3,9 @@ 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';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import * as Sentry from '@sentry/sveltekit';
|
|
||||||
export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
||||||
const id = BigInt(params.id);
|
const id = BigInt(params.id);
|
||||||
const preciosQuery = db
|
const preciosRes = await db
|
||||||
.select({
|
.select({
|
||||||
id_comercio: precios.id_comercio,
|
id_comercio: precios.id_comercio,
|
||||||
id_bandera: precios.id_bandera,
|
id_bandera: precios.id_bandera,
|
||||||
|
@ -48,15 +47,6 @@ ORDER BY d1.id_comercio)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.leftJoin(datasets, eq(datasets.id, precios.id_dataset));
|
.leftJoin(datasets, eq(datasets.id, precios.id_dataset));
|
||||||
const preciosRes = await Sentry.startSpan(
|
|
||||||
{
|
|
||||||
op: 'db.query',
|
|
||||||
name: preciosQuery.toSQL().sql,
|
|
||||||
data: { 'db.system': 'postgresql' }
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
} as any,
|
|
||||||
() => preciosQuery
|
|
||||||
);
|
|
||||||
|
|
||||||
setHeaders({
|
setHeaders({
|
||||||
'Cache-Control': 'public, max-age=600'
|
'Cache-Control': 'public, max-age=600'
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { db } from '$lib/server/db';
|
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';
|
||||||
import * as Sentry from '@sentry/sveltekit';
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
||||||
// const latestDatasetsSq = db.$with('latest_datasets').as(
|
// const latestDatasetsSq = db.$with('latest_datasets').as(
|
||||||
|
@ -24,7 +23,12 @@ export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
||||||
.replaceAll(/ó/giu, 'o')
|
.replaceAll(/ó/giu, 'o')
|
||||||
.replaceAll(/ú/giu, 'u')
|
.replaceAll(/ú/giu, 'u')
|
||||||
.replaceAll(/ñ/giu, 'n');
|
.replaceAll(/ñ/giu, 'n');
|
||||||
const productosQuery = sql`
|
const productos = await db.execute<{
|
||||||
|
id_producto: string;
|
||||||
|
productos_descripcion: string;
|
||||||
|
productos_marca: string | null;
|
||||||
|
in_datasets_count: number;
|
||||||
|
}>(sql`
|
||||||
SELECT id_producto, productos_descripcion, productos_marca,
|
SELECT id_producto, productos_descripcion, productos_marca,
|
||||||
(WITH latest_datasets AS (
|
(WITH latest_datasets AS (
|
||||||
SELECT d1.id
|
SELECT d1.id
|
||||||
|
@ -42,22 +46,7 @@ WHERE p.id_producto = index.id_producto) as in_datasets_count
|
||||||
WHERE productos_descripcion ILIKE ${`%${query}%`}
|
WHERE productos_descripcion ILIKE ${`%${query}%`}
|
||||||
ORDER BY in_datasets_count desc
|
ORDER BY in_datasets_count desc
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
`;
|
`);
|
||||||
const productos = await Sentry.startSpan(
|
|
||||||
{
|
|
||||||
op: 'db.query',
|
|
||||||
name: productosQuery,
|
|
||||||
data: { 'db.system': 'postgresql' }
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
} as any,
|
|
||||||
() =>
|
|
||||||
db.execute<{
|
|
||||||
id_producto: string;
|
|
||||||
productos_descripcion: string;
|
|
||||||
productos_marca: string | null;
|
|
||||||
in_datasets_count: number;
|
|
||||||
}>(productosQuery)
|
|
||||||
);
|
|
||||||
const collapsedProductos = productos.reduce(
|
const collapsedProductos = productos.reduce(
|
||||||
(acc, producto) => {
|
(acc, producto) => {
|
||||||
const existingProduct = acc.find((p) => p.id_producto === producto.id_producto);
|
const existingProduct = acc.find((p) => p.id_producto === producto.id_producto);
|
||||||
|
|
Loading…
Reference in a new issue