varios cambios esteticos y optimizaciones

This commit is contained in:
jlimolina 2025-11-25 03:13:54 +01:00
parent e3a99d9604
commit 9a243db633
8 changed files with 64 additions and 105 deletions

View file

@ -1,51 +1,27 @@
BEGIN;
-- =============================================
-- Sistema de eventos (clustering incremental)
-- =============================================
-- ---------------------------------------------
-- 1. TABLA DE EVENTOS (CLUSTERS)
-- ---------------------------------------------
CREATE TABLE IF NOT EXISTS eventos (
id BIGSERIAL PRIMARY KEY,
creado_en TIMESTAMPTZ NOT NULL DEFAULT NOW(),
actualizado_en TIMESTAMPTZ NOT NULL DEFAULT NOW(),
-- Datos "semánticos" del evento (para la web)
titulo TEXT,
fecha_inicio TIMESTAMPTZ,
fecha_fin TIMESTAMPTZ,
n_noticias INTEGER NOT NULL DEFAULT 0,
-- Datos de clustering
centroid JSONB NOT NULL,
total_traducciones INTEGER NOT NULL DEFAULT 1
);
-- ---------------------------------------------
-- 2. COLUMNA evento_id EN TRADUCCIONES
-- ---------------------------------------------
ALTER TABLE traducciones
ADD COLUMN IF NOT EXISTS evento_id BIGINT REFERENCES eventos(id);
-- ---------------------------------------------
-- 3. TABLA RELACIÓN EVENTO <-> NOTICIA <-> TRADUCCIÓN
-- (tipos alineados con noticias.id (VARCHAR(32))
-- y traducciones.id (INTEGER))
-- ---------------------------------------------
CREATE TABLE IF NOT EXISTS eventos_noticias (
evento_id BIGINT NOT NULL REFERENCES eventos(id) ON DELETE CASCADE,
noticia_id VARCHAR(32) NOT NULL REFERENCES noticias(id) ON DELETE CASCADE,
traduccion_id INTEGER NOT NULL REFERENCES traducciones(id) ON DELETE CASCADE,
PRIMARY KEY (evento_id, traduccion_id)
PRIMARY KEY (evento_id, noticia_id)
);
-- ---------------------------------------------
-- 4. ÍNDICES ÚTILES
-- ---------------------------------------------
-- Consultar traducciones por evento
CREATE INDEX IF NOT EXISTS idx_traducciones_evento
ON traducciones(evento_id);
@ -55,11 +31,9 @@ CREATE INDEX IF NOT EXISTS idx_traducciones_evento_fecha
CREATE INDEX IF NOT EXISTS idx_trad_id
ON traducciones(id);
-- Ordenar eventos por fecha de inicio
CREATE INDEX IF NOT EXISTS idx_eventos_fecha_inicio
ON eventos (fecha_inicio DESC NULLS LAST);
-- Relación evento <-> noticia / traducción
CREATE INDEX IF NOT EXISTS idx_eventos_noticias_evento
ON eventos_noticias (evento_id);
@ -69,9 +43,6 @@ CREATE INDEX IF NOT EXISTS idx_eventos_noticias_noticia
CREATE INDEX IF NOT EXISTS idx_eventos_noticias_traduccion
ON eventos_noticias (traduccion_id);
-- ---------------------------------------------
-- 5. TRIGGER PARA actualizar "actualizado_en"
-- ---------------------------------------------
CREATE OR REPLACE FUNCTION actualizar_evento_modificado()
RETURNS TRIGGER AS $$
BEGIN