From 7ca44d7df17898d5821e29d5d80a2dfe36b2b33d Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 9 May 2026 15:08:16 +0200 Subject: [PATCH] fix(db): add indexes on documents.sender_id and document_comments.author_id Flyway V62 adds idx_documents_sender_id and idx_comments_author_id to speed up FK-driven queries on the persons page and briefwechsel view. Closes #470. Co-Authored-By: Claude Sonnet 4.6 --- .../db/migration/V62__index_fk_columns.sql | 8 ++++++++ .../MigrationIntegrationTest.java | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 backend/src/main/resources/db/migration/V62__index_fk_columns.sql diff --git a/backend/src/main/resources/db/migration/V62__index_fk_columns.sql b/backend/src/main/resources/db/migration/V62__index_fk_columns.sql new file mode 100644 index 00000000..4cbb254c --- /dev/null +++ b/backend/src/main/resources/db/migration/V62__index_fk_columns.sql @@ -0,0 +1,8 @@ +-- Speeds up "documents by sender" queries used on /persons/[id] Korrespondenz-Überblick (#306), +-- /briefwechsel, and bulk-edit flows. +CREATE INDEX IF NOT EXISTS idx_documents_sender_id + ON documents(sender_id); + +-- Speeds up "comments by author" queries on admin user detail and (future) contributor profile. +CREATE INDEX IF NOT EXISTS idx_comments_author_id + ON document_comments(author_id); diff --git a/backend/src/test/java/org/raddatz/familienarchiv/MigrationIntegrationTest.java b/backend/src/test/java/org/raddatz/familienarchiv/MigrationIntegrationTest.java index a01682ab..425d0f59 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/MigrationIntegrationTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/MigrationIntegrationTest.java @@ -399,6 +399,24 @@ class MigrationIntegrationTest { AND dc.annotation_id IS NOT NULL """; + // ─── V62: indexes on FK columns ────────────────────────────────────────── + + @Test + void v62_idx_documents_sender_id_exists() { + Integer count = jdbc.queryForObject( + "SELECT COUNT(*) FROM pg_catalog.pg_indexes WHERE tablename = 'documents' AND indexname = 'idx_documents_sender_id'", + Integer.class); + assertThat(count).isEqualTo(1); + } + + @Test + void v62_idx_comments_author_id_exists() { + Integer count = jdbc.queryForObject( + "SELECT COUNT(*) FROM pg_catalog.pg_indexes WHERE tablename = 'document_comments' AND indexname = 'idx_comments_author_id'", + Integer.class); + assertThat(count).isEqualTo(1); + } + // ─── V63+V64: group_permissions dedup + primary key ────────────────────── @Test -- 2.49.1