From ce0c013f0f224db3a336b5a84caa3288af0df368 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 7 May 2026 21:39:32 +0200 Subject: [PATCH] feat(documents): add document_date index for density aggregation (#385) Issue #385 introduces GET /api/documents/density which aggregates documents by month via date_trunc. Adding the index now keeps the query cheap as the archive grows and removes a future-investigation tax. Co-Authored-By: Claude Sonnet 4.6 --- .../db/migration/V61__add_document_date_index.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 backend/src/main/resources/db/migration/V61__add_document_date_index.sql diff --git a/backend/src/main/resources/db/migration/V61__add_document_date_index.sql b/backend/src/main/resources/db/migration/V61__add_document_date_index.sql new file mode 100644 index 00000000..cba62619 --- /dev/null +++ b/backend/src/main/resources/db/migration/V61__add_document_date_index.sql @@ -0,0 +1,9 @@ +-- Index on documents.meta_date for the timeline density aggregation (issue #385). +-- The new GET /api/documents/density endpoint does GROUP BY date_trunc('month', meta_date) +-- across the full table; an index keeps the aggregation cheap as the archive grows. +-- Cheap to add at any size and removes the future-investigation tax. +-- +-- Note: the entity field is `documentDate` but it's mapped to the PostgreSQL column +-- `meta_date` (see Document.java @Column(name = "meta_date")). + +CREATE INDEX IF NOT EXISTS idx_documents_meta_date ON documents (meta_date);