Skip to content

fix: optimize project queue total count - #9862

Closed
fredheir wants to merge 1 commit into
HumanSignal:developfrom
fredheir:codex/perf-queue-total-count
Closed

fix: optimize project queue total count#9862
fredheir wants to merge 1 commit into
HumanSignal:developfrom
fredheir:codex/perf-queue-total-count

Conversation

@fredheir

@fredheir fredheir commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Reason for change

ProjectSerializer.get_queue_total currently combines a negated annotation relation, a positive annotation relation, and distinct().count(). Django compiles that to a duplicate-producing outer join plus an anti-subquery and DISTINCT. This PR expresses the same membership rule directly as unlabeled OR EXISTS(current-user annotation).

Fixes #9861.

Performance evidence

Read-only PostgreSQL A/B tests on three representative project/user pairs preserved exact counts and reduced server execution time:

  • 268.2 ms -> 16.3 ms
  • 31.5 ms -> 9.5 ms
  • 35.9 ms -> 7.5 ms

The PostgreSQL ORM SQL for the candidate uses one correlated EXISTS, with no outer annotation join or DISTINCT.

Testing

  • projects/tests/test_serializers.py: 17 passed on SQLite
  • Ruff check and format: passed
  • Regression matrix covers unlabeled tasks, current-user annotations, other-user annotations, and mixed annotations
  • Test asserts one count query, EXISTS present, and DISTINCT absent
  • Live PostgreSQL exact-result parity verified for all three A/B cases

Acceptance criteria

  • Exact task-membership parity with the existing predicate
  • One count query
  • Correlated EXISTS; no outer annotation join or DISTINCT
  • SQLite and PostgreSQL-compatible ORM query

Rollout and risk

No schema or API contract change is involved. The risk is limited to task-membership equivalence; the regression matrix and live exact-result comparisons cover that boundary. No feature flag is needed.

@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

👷 Deploy request for heartex-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2aeee5f

@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

👷 Deploy request for label-studio-docs-new-theme pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2aeee5f

@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

Deploy Preview for label-studio-storybook canceled.

Name Link
🔨 Latest commit 2aeee5f
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/6a6df0f350f144000859ddfa

@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

Deploy Preview for label-studio-playground canceled.

Name Link
🔨 Latest commit 2aeee5f
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-playground/deploys/6a6df0f3a75e680008fc0b5c

robot-ci-heartex added a commit that referenced this pull request Aug 10, 2026
Closes #9862

GitOrigin-RevId: 04456b61c62deb8ab003bada17137ac3f706c550
nikitabelonogov pushed a commit that referenced this pull request Aug 10, 2026
Empty attribution commit: f329f6e was authored by Rolf Fredheim
<rolf@markolo.eu> (#9862); the authorship was
lost when the mirrored PR was squash-merged internally.
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.

Project queue_total count creates an expensive duplicate-producing join

1 participant