Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add index creation for matviews (#280)

Madison Swain-Bowdenef614b9789f4
diff --git a/docker/local_postgres/0004_openledger_image_view.sql b/docker/local_postgres/0004_openledger_image_view.sql
index 313136f51..99a61ee56 100644
--- a/docker/local_postgres/0004_openledger_image_view.sql
+++ b/docker/local_postgres/0004_openledger_image_view.sql
@@ -36,6 +36,7 @@ CREATE MATERIALIZED VIEW public.image_popularity_constants AS
SELECT *, ((1 - percentile) / percentile) * val AS constant
FROM popularity_metric_values;
+CREATE UNIQUE INDEX ON image_popularity_constants (provider);
CREATE FUNCTION standardized_image_popularity(provider text, meta_data jsonb)
@@ -79,3 +80,5 @@ CREATE MATERIALIZED VIEW image_view AS
image.provider, image.meta_data
) AS standardized_popularity
FROM image;
+
+CREATE UNIQUE INDEX ON image_view (identifier);
diff --git a/docker/local_postgres/0007_openledger_audio_view.sql b/docker/local_postgres/0007_openledger_audio_view.sql
index 1d11dbb0d..88b3d6038 100644
--- a/docker/local_postgres/0007_openledger_audio_view.sql
+++ b/docker/local_postgres/0007_openledger_audio_view.sql
@@ -35,6 +35,7 @@ CREATE MATERIALIZED VIEW public.audio_popularity_constants AS
SELECT *, ((1 - percentile) / percentile) * val AS constant
FROM popularity_metric_values;
+CREATE UNIQUE INDEX ON audio_popularity_constants (provider);
CREATE FUNCTION standardized_audio_popularity(provider text, meta_data jsonb)
@@ -82,3 +83,5 @@ CREATE MATERIALIZED VIEW audio_view AS
audio.provider, audio.meta_data
) AS standardized_popularity
FROM audio;
+
+CREATE UNIQUE INDEX ON audio_view (identifier);