Skip to content

Add include_archived support to Advanced Search work items finder

What does this MR do and why?

Add include_archived support to Advanced Search work items finder

GLQL queries were falling back to PostgreSQL instead of using Elasticsearch (Advanced Search), causing timeouts on large namespaces like gitlab-org.

#573896

Problem

When users execute GLQL queries or use the Work Items list with Advanced Search enabled, all queries were unexpectedly falling back to PostgreSQL, resulting in:

  • Query timeouts on large namespaces (e.g., gitlab-org with thousands of work items)
  • Degraded performance for users with Advanced Search enabled
  • ES feature essentially being disabled for all GLQL/Work Items queries

Example query that would timeout:

query: group = "gitlab-org" and label = "type::bug"
fields: title, createdAt
title: Open bugs

Root Cause

The include_archived parameter was added to Namespaces::WorkItemsResolver in GitLab 18.5 (commit 48bad4f755b2, Oct 1, 2025) !207030 (merged) with default_value: false. GraphQL automatically includes this parameter in every work items query, but it was not present in the Advanced Finder's ALLOWED_ES_FILTERS list.

This caused the validation in allowed_main_filters? to fail:

filter_keys = params.keys - CONTROL_KEYS
# => [:label_name, :include_archived]

(filter_keys - ALLOWED_ES_FILTERS).empty?
# => false (because :include_archived was not in ALLOWED_ES_FILTERS)

When validation failed, use_elasticsearch_finder? returned false, causing all queries to fall back to PostgreSQL.

Solution

This MR adds full support for the include_archived parameter:

  1. Adds :include_archived to ALLOWED_ES_FILTERS - Allows validation to pass
  2. Passes include_archived to Elasticsearch - Implements proper filtering via existing Search::Elastic::Filters.by_archived
  3. Adds comprehensive specs - Tests the functionality end-to-end with real ES queries
  4. Adds regression protection - Ensures future resolver arguments must be handled by the Advanced Finder

References

Related commits:

  • Introduction of include_archived: 48bad4f755b2 (Oct 1, 2025) !207030 (merged)
  • Elasticsearch archived filtering: Already existed in ee/lib/search/elastic/filters.rb:778

Screenshots or screen recordings

N/A - Backend-only change

How to set up and validate locally

  1. Enable Elasticsearch and the feature flag:

    # In rails console
    Feature.enable(:glql_es_integration)
  2. Ensure Elasticsearch is running and indexed:

    gdk status zoekt
    # Or check ES status in admin panel
  3. Create test data with archived projects:

    # In rails console
    group = Group.find_by(full_path: 'gitlab-org')
    archived_project = FactoryBot.create(:project, :archived, group: group)
    active_project = FactoryBot.create(:project, group: group)
    
    work_item_archived = FactoryBot.create(:work_item, project: archived_project)
    work_item_active = FactoryBot.create(:work_item, project: active_project)
    
    # Index in ES
    Elastic::ProcessBookkeepingService.track!(work_item_archived, work_item_active)
  4. Test GLQL queries:

    # Default behavior (should exclude archived projects)
    query: group = "gitlab-org" and state = opened
    fields: title
    title: Active work items
    
    # Explicit includeArchived=false (same as default)
    # (This would need to be tested via GraphQL API)
  5. Verify ES is being used:

    • Queries should complete quickly (milliseconds, not seconds/timeout)
    • Check logs for ES queries, not PostgreSQL queries
    • Archived project work items should be excluded by default

Test Results

All specs pass:

$ bin/rspec ee/spec/lib/ee/search/advanced_finders/work_items_finder_spec.rb

118 examples, 0 failures

Key tests added:

  • when include_archived is false - Excludes archived projects ✓
  • when include_archived is true - Includes archived projects ✓
  • when include_archived is not specified - Defaults to excluding archived ✓
  • all GROUP_NAMESPACE_ONLY_ARGS are in CONTROL_KEYS or ALLOWED_ES_FILTERS - Regression protection ✓

MR acceptance checklist

This MR has been evaluated against the MR acceptance checklist.

Specific considerations:

  • Correctness: Fixes the PostgreSQL fallback bug and implements proper ES filtering
  • Performance: Critical fix - prevents timeouts by using ES instead of PostgreSQL on large namespaces
  • Reliability: Comprehensive test coverage with 118 passing specs
  • Security: No security implications - uses existing ES filtering
  • Testing: Added 3 new specs for include_archived functionality + regression test
  • Backward compatibility: Maintains existing behavior (excluding archived by default)
  • Documentation: Code is well-commented, spec explains the purpose
  • Code quality: Follows existing patterns, RuboCop compliant
Edited by Dmitry Gruzd

Merge request reports

Loading