Skip to content

Reduce over-fetching in Bugscache queries#9554

Open
camd wants to merge 1 commit into
masterfrom
camd/query-optimization-bugscache
Open

Reduce over-fetching in Bugscache queries#9554
camd wants to merge 1 commit into
masterfrom
camd/query-optimization-bugscache

Conversation

@camd
Copy link
Copy Markdown
Collaborator

@camd camd commented May 25, 2026

Summary

Bugscache.search() (backing the bug-suggestions endpoint) and the create_bug endpoint both loaded full Bugscache rows when only a subset of columns is actually used. This trims the fetched/written columns without changing behavior.

Changes

  • Bugscache.search() — add .only(...) to defer modified and processed_update, which serialize() excludes anyway. The TrigramSimilarity annotation and serialize() output are unaffected.
  • Bugscache.serialize() — remove the dead "jobmap" entry from exclude_fields; it's a reverse relation that model_to_dict never iterates, so it had no effect.
  • create_bug — resolve the existing internal id with values_list("id", flat=True).first() instead of fetching the whole row; restrict the summary-fallback query with .only("id", "bugzilla_id", "modified"); and limit the linking save() to the two changed columns via update_fields.

Tests

Added coverage for the create_bug internal-id resolution paths (existing bug matched by bugzilla_id, and an internal bug linked by summary), which were previously untested.

Notes

This is the over-fetch portion of a broader Bugscache query audit. A separate, layered PR adds a GIN trigram index on bugscache.summary (the substring/similarity search currently can't use the existing btree index) — kept separate so the index change can be measured and reviewed on its own.

Bugscache.search() and the create_bug endpoint loaded full Bugscache
rows when only a subset of columns is actually used:

- search(): defer `modified` and `processed_update` via .only(), since
  serialize() excludes them anyway. Remove the dead `jobmap` entry from
  the serialize() exclude list (a reverse relation model_to_dict never
  iterates).
- create_bug: resolve the existing bug id with values_list() instead of
  fetching the whole row, restrict the summary fallback query with
  .only(), and limit the linking save() to the two changed columns via
  update_fields.

Add tests covering the create_bug internal-id resolution paths.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.96%. Comparing base (6e680ff) to head (bf76b0f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9554      +/-   ##
==========================================
+ Coverage   82.94%   82.96%   +0.02%     
==========================================
  Files         613      613              
  Lines       35372    35394      +22     
  Branches     3208     3206       -2     
==========================================
+ Hits        29338    29364      +26     
+ Misses       5880     5876       -4     
  Partials      154      154              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants