Explorar el Código

Add a main_page_apparitions view

jherve hace 1 año
padre
commit
b4f74bad0b
Se han modificado 1 ficheros con 19 adiciones y 0 borrados
  1. 19 0
      src/de_quoi_parle_le_monde/storage.py

+ 19 - 0
src/de_quoi_parle_le_monde/storage.py

@@ -234,6 +234,25 @@ class Storage:
                 """
             )
 
+            await conn.execute(
+                """
+                CREATE VIEW IF NOT EXISTS main_page_apparitions AS
+                    SELECT
+                        fas.id,
+                        fas.featured_article_id,
+                        fas.title,
+                        fas.url AS url_archive,
+                        fa.url AS url_article,
+                        m.snapshot_id AS main_in_snapshot_id,
+                        t.snapshot_id AS top_in_snapshot_id,
+                        t.rank
+                    FROM featured_article_snapshots fas
+                    JOIN featured_articles fa ON fa.id = fas.featured_article_id
+                    LEFT JOIN main_articles m ON m.featured_article_snapshot_id = fas.id
+                    LEFT JOIN top_articles t ON t.featured_article_snapshot_id = fas.id
+                """
+            )
+
             await conn.execute(
                 """
                 CREATE TABLE IF NOT EXISTS articles_embeddings (