From e9f9f5ddedcba01ec3bc088b8daeeada32bb816c Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 6 Jun 2024 17:33:42 +0800 Subject: [PATCH] add index for user_id column on highlight table --- packages/api/test/resolvers/highlight.test.ts | 13 ++++++++----- .../0178.do.add_index_on_highlight_user_id.sql | 5 +++++ .../0178.undo.add_index_on_highlight_user_id.sql | 9 +++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100755 packages/db/migrations/0178.do.add_index_on_highlight_user_id.sql create mode 100755 packages/db/migrations/0178.undo.add_index_on_highlight_user_id.sql diff --git a/packages/api/test/resolvers/highlight.test.ts b/packages/api/test/resolvers/highlight.test.ts index 34cc811eb..b51e93b37 100644 --- a/packages/api/test/resolvers/highlight.test.ts +++ b/packages/api/test/resolvers/highlight.test.ts @@ -459,16 +459,19 @@ describe('Highlights API', () => { const label1 = await createLabel(labelName1, '#ff0001', user.id) // save labels in highlights - await saveLabelsInHighlight([label], existingHighlights[0].id, user.id) - await saveLabelsInHighlight([label1], existingHighlights[1].id, user.id) + await saveLabelsInHighlight( + [label, label1], + existingHighlights[0].id, + user.id + ) const res = await graphqlRequest(query, authToken, { query: `label:"${labelName}" label:"${labelName1}"`, }).expect(200) const highlights = res.body.data.highlights.edges as Array - expect(highlights).to.have.lengthOf(2) - expect(highlights[1].node.labels?.[0].name).to.eq(labelName) - expect(highlights[0].node.labels?.[0].name).to.eq(labelName1) + expect(highlights).to.have.lengthOf(1) + expect(highlights[0].node.labels?.[0].name).to.eq(labelName) + expect(highlights[0].node.labels?.[1].name).to.eq(labelName1) await deleteLabels([label.id, label1.id], user.id) }) diff --git a/packages/db/migrations/0178.do.add_index_on_highlight_user_id.sql b/packages/db/migrations/0178.do.add_index_on_highlight_user_id.sql new file mode 100755 index 000000000..b88fc8111 --- /dev/null +++ b/packages/db/migrations/0178.do.add_index_on_highlight_user_id.sql @@ -0,0 +1,5 @@ +-- Type: DO +-- Name: add_index_on_highlight_user_id +-- Description: Add index on user_id column to the highlight table + +CREATE INDEX CONCURRENTLY IF NOT EXISTS highlight_user_id_idx ON omnivore.highlight (user_id); diff --git a/packages/db/migrations/0178.undo.add_index_on_highlight_user_id.sql b/packages/db/migrations/0178.undo.add_index_on_highlight_user_id.sql new file mode 100755 index 000000000..387c61d6f --- /dev/null +++ b/packages/db/migrations/0178.undo.add_index_on_highlight_user_id.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: add_index_on_highlight_user_id +-- Description: Add index on user_id column to the highlight table + +BEGIN; + +DROP INDEX IF EXISTS highlight_user_id_idx; + +COMMIT;