Skip to content

fix: optimize project queue total count - #9881

Closed
nikitabelonogov wants to merge 2 commits into
developfrom
codex/perf-queue-total-count
Closed

fix: optimize project queue total count#9881
nikitabelonogov wants to merge 2 commits into
developfrom
codex/perf-queue-total-count

Conversation

@nikitabelonogov

Copy link
Copy Markdown
Member

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.

This PR is a mirror for #9862

@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit 0ece0d6
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-docs-new-theme/deploys/6a7a22ad5f44bd0008023bde

@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit 0ece0d6
🔍 Latest deploy log https://app.netlify.com/projects/heartex-docs/deploys/6a7a22ade3c42e0008a0023e

@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for label-studio-storybook failed. Why did it fail? →

Name Link
🔨 Latest commit 0ece0d6
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/6a7a22adf2c14b00081a81d8

@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for label-studio-playground failed. Why did it fail? →

Name Link
🔨 Latest commit 0ece0d6
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-playground/deploys/6a7a22ad784ee1000828ed3a

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project queue_total count creates an expensive duplicate-producing join

2 participants