Skip to content

⚡️(backend) search users through the trigram indexes - #2906

Merged
lunika merged 1 commit into
mainfrom
investigation/postgres-spikes
Oct 23, 2026
Merged

lunika merged 1 commit into
mainfrom
investigation/postgres-spikes

Conversation

@lunika

@lunika lunika commented Oct 23, 2026

Copy link
Copy Markdown
Member

Purpose

The user search filtered on a similarity score computed on the raw email and full_name columns. The trigram indexes are built on f_unaccent(email) and f_unaccent(full_name) and only serve the % operator, so each search scanned the whole user table, and all the matches were then filtered and sorted in Python.

The search now uses the % operator on the indexed expressions, with a similarity threshold scoped to the transaction. It filters the shared and same-domain users in SQL, and fetches no more users than the response limit.

Proposal

  • ⚡️(backend) search users through the trigram indexes

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b1ea8261-933f-47f7-8289-99e81c7c22ff
📥 Commits

Reviewing files that changed from the base of the PR and between b61ab0a and 47609af.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ea060312-5da8-45be-9477-4dcfb5078d83
📥 Commits

Reviewing files that changed from the base of the PR and between 9c233b8 and b61ab0a.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • src/backend/core/api/viewsets.py
  • src/backend/core/tests/test_api_users.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Backend user searches now use unaccented trigram matching to find email and full-name candidates. Email searches also apply a Levenshtein distance limit. Other searches place shared-document users before same-domain matches and cap the combined results. The search sets a transaction-local trigram threshold. Tests check result ordering, index use, and threshold reset.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: antolc

Merge Risk: ⚪ Minimal · up to b61ab

No issue requiring a fix before merge was established; the change is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the primary change: user search now uses the trigram indexes. The changeset replaces the raw-column similarity scoring with % operator queries on the f_unaccent(email) and f_unaccent(f…
Description check Passed The description states the problem: the search used a similarity score on raw email and full_name columns, so the trigram indexes (built on f_unaccent expressions and used only by the % operator) were…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the primary change: user search now uses the trigram indexes. The changeset replaces the raw-column similarity scoring with % operator queries on the f_unaccent(email) and f_unaccent(full_name) indexed expressions, and moves shared and same-domain filtering into SQL. The title is short and specific. It does not cover the transaction-scoped threshold or the result limit, which is acceptable.

Full details: Description check

Explanation

The description states the problem: the search used a similarity score on raw email and full_name columns, so the trigram indexes (built on f_unaccent expressions and used only by the % operator) were not used and every search scanned the user table. It also describes the fix: the % operator on the indexed expressions, a transaction-scoped threshold, SQL-side filtering of shared and same-domain users, and a fetch limit. This matches the viewsets.py and test changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The user search filtered on a similarity score computed on the raw
email and full_name columns. The trigram indexes are built on
f_unaccent(email) and f_unaccent(full_name) and only serve the %
operator, so each search scanned the whole user table, and all the
matches were then filtered and sorted in Python.

The search now uses the % operator on the indexed expressions, with
a similarity threshold scoped to the transaction. It filters the
shared and same-domain users in SQL, and fetches no more users than
the response limit.
@lunika
lunika force-pushed the investigation/postgres-spikes branch from b61ab0a to 47609af Compare October 23, 2026 15:36
@lunika
lunika merged commit 47609af into main Oct 23, 2026
50 checks passed
@lunika
lunika deleted the investigation/postgres-spikes branch October 23, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant