feat: add index for member api (CM-764)#3588
Merged
Merged
Conversation
themarolt
approved these changes
Nov 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add database indexes to improve member query performance
Summary
This PR introduces three new indexes aimed at optimizing search and ranking queries
executed by the
/member/queryendpoint and related aggregation logic.Rationale
idx_msa_segment_activitycount_desc_memberEnables efficient retrieval of the top active members within a segment,
removing the need for expensive sorts on large result sets.
idx_members_displayname_trgmImproves performance of text searches by display name
(
LOWER(displayName) LIKE '%term%'), commonly used in the search feature.idx_memberidentities_email_verified_trgmAccelerates lookups of verified email identities
(
LOWER(value) LIKE '%term%'), reducing scan cost onmemberIdentities.Note
Add three concurrent Postgres indexes to speed member queries, display name search, and verified email lookups.
backend/src/database/migrations/V1762789440__optimize_member_api.sql):idx_msa_segment_activitycount_desc_memberonpublic."memberSegmentsAgg" ("segmentId", "activityCount" DESC, "memberId").idx_members_displayname_trgmGIN onpublic."members"usingLOWER("displayName") gin_trgm_ops.idx_memberidentities_email_verified_trgmGIN onpublic."memberIdentities"usingLOWER("value") gin_trgm_opswith partial filterWHERE verified = true AND type = 'email'.Written by Cursor Bugbot for commit d17a4e0. This will update automatically on new commits. Configure here.