Skip to content

[Hot-Fix] ISS-281939: Two-phase query optimisation for IssueViewSet#283

Merged
ritchaddha merged 2 commits intostagingfrom
hotfix/ISS-281939/project-issues-endpoint-optimisation-staging
Feb 25, 2026
Merged

[Hot-Fix] ISS-281939: Two-phase query optimisation for IssueViewSet#283
ritchaddha merged 2 commits intostagingfrom
hotfix/ISS-281939/project-issues-endpoint-optimisation-staging

Conversation

@harsh-yadav-shipsy
Copy link

@harsh-yadav-shipsy harsh-yadav-shipsy commented Feb 25, 2026

Summary

Applies the same two-phase query strategy already shipped on WorkspaceViewIssuesViewSet to IssueViewSet (GET /api/workspaces/{slug}/projects/{id}/issues/).

The problem: The old get_queryset() ran 5 correlated subqueries + 4 select_related JOINs + 3 prefetch_related calls against the entire unfiltered dataset before pagination. On large projects (10k+ issues) this was the primary bottleneck.

The fix — three phases:

  • Phase 1 (get_queryset): lean Issue.objects queryset — only scalar filters + one cycle_id annotation. Handles filtering, ordering, and pagination.
  • Phase 2 (_build_detail_queryset): count subqueries (sub_issues_count, link_count, attachment_count) run against ~100 paginated IDs only.
  • Phase 3 (_enrich_issues_with_relations): 5 flat IN-queries batch-load label_ids, assignee_ids, module_ids, cycle_id, custom_property_values.

Additional fixes:

  • create() was broken after get_queryset() was made lean — now uses _build_detail_queryset + _enrich_issues_with_relations.
  • Dead import issue_on_results removed.
  • Phase-1/Phase-2 null-state mismatch fixed by adding state_id__isnull=False to Phase 1 filter in both IssueViewSet and WorkspaceViewIssuesViewSet.
  • Debug logger.debug statements added to IssueViewSet for Phase 1 and Phase 2 SQL.

Ticket Information

Link: ISS-281939

How to Test

  1. Hit GET /api/workspaces/{slug}/projects/{id}/issues/?layout=list — confirm issues returned with correct label_ids, assignee_ids, module_ids, cycle_id, custom_property_values.
  2. Hit with group_by=assignees__id — confirm grouped response; assignees correctly split per group row.
  3. Hit with group_by=labels__id&sub_group_by=state_id — confirm sub-grouped response.
  4. Hit with group_by=priority (non-M2M) — confirm ordering preserved correctly.
  5. Create a new issue via POST /api/workspaces/{slug}/projects/{id}/issues/ — confirm the 201 response includes sub_issues_count, link_count, attachment_count, label_ids, cycle_id.
  6. As a guest user (role=5, guest_view_all_features=False) — confirm only created_by=me issues returned.
  7. Check Django logs at DEBUG level — Phase 1 and Phase 2 SQL should be visible for IssueViewSet.

harsh-yadav-shipsy and others added 2 commits February 25, 2026 13:28
…nd WorkspaceViewIssuesViewSet

Applies the same two-phase strategy already proven on WorkspaceViewIssuesViewSet
to IssueViewSet (GET /api/workspaces/{slug}/projects/{id}/issues/).

Phase 1 – lean queryset (Issue.objects, no JOINs/annotations beyond cycle_id)
handles filtering, ordering, and pagination across the full dataset.
Phase 2 – _build_detail_queryset runs the 3 count subqueries on ~100 IDs.
Phase 3 – _enrich_issues_with_relations batch-loads label_ids, assignee_ids,
module_ids, cycle_id, and custom_property_values via 5 flat IN-queries.

Also fixes:
- create() was broken after get_queryset() was made lean (FieldError on
  sub_issues_count / link_count / attachment_count); now uses _build_detail_queryset
  + _enrich_issues_with_relations.
- Dead import issue_on_results removed.
- Phase-1/Phase-2 null-state mismatch closed by adding state_id__isnull=False
  to Phase 1 filter (Django's exclude+IN adds OR IS NULL; Phase 2 inner-joins
  on state, which drops null-state rows).
- Debug logger statements added to IssueViewSet for Phase 1 and Phase 2 SQL.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ritchaddha ritchaddha merged commit d2777c6 into staging Feb 25, 2026
7 of 8 checks passed
@ritchaddha ritchaddha deleted the hotfix/ISS-281939/project-issues-endpoint-optimisation-staging branch February 25, 2026 09:17
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