Skip to content

Content Drive: field filter re-scans the folder candidate query up to 4x per request #37184

Description

@ihoffmann-dot

Description

When a Content Drive field filter (e.g. a Text field contains-match) is fully resolvable against the search index — no Tag, no Relationship, no workflow, no free-text term — the system still repeats the expensive database candidate-scan query multiple times per request instead of once. On a ~21,000-item folder this took ~4 repeats and made the response ~6x slower than an equivalent search (606ms vs 88ms).

The routing to the index is correct per ADR-0018 (fields flagged searchable on the content type are index-resolved by design — this is not a mis-routing bug). The inefficiency is in the DB-first hybrid chunk loop, which keeps re-scanning in fixed-size chunks (BROWSER_CONTENT_CHUNK_SIZE, default 900) until enough matches survive index narrowing, regardless of match density.

buildPureESQuery (BrowserAPIImpl) already builds nearly everything needed for a single-pass, index-only query for this specific case, but is missing a folder-scoping clause (conFolder, an already-used, low-risk ES field). Adding it and routing to this path only when zero DB-routed criteria, no workflow filter, and no free-text term are present should collapse the repeated scans to one.


Adding some independent measurements that corroborate this issue, gathered testing against a large dataset (~718,174 contentlets):

  • Filtering by a specific searchable field (Content Type: File Asset + File Name filter) took ~2 minutes to return a response, versus ~31.5 seconds for the equivalent global search filter term — roughly 3.8x slower, consistent with the field-filter re-scan behavior described here.
  • Combining a secondary-language filter with the global search filter took ~12 seconds to generate a response.
  • A plain global search in Content Drive took ~25 seconds to return results, versus ~24ms for the same term in the Search All portlet.

These numbers are from a larger dataset than referenced in the issue description, so the relative slowdown compounds further at scale — an additional data point for the "falls within 20% of an equivalent content-search operation" acceptance criterion.

Acceptance Criteria

  • A field filter with no DB-required criteria over a large folder resolves with at most one database candidate-scan, not four
  • Response time for that case falls to within 20% of an equivalent content-search operation
  • Filters combined with Tag, Relationship, workflow, or free-text terms are unaffected — same result sets, same database-first resolution, no behavior change
  • Result sets for Text, Date-range, Multi-select, and Category field filters are unchanged from current behavior
  • The mandatory read-permission filter continues to run, sourced from the database, on every request
  • No dedicated feature flag — ships as default behavior; the general search-strategy config remains the fallback escape hatch

Coordination note

Shares the underlying candidate-scan query with #37183 (spike on that query's plan instability). Whatever #37183 changes about that query must continue to work correctly when invoked at most once per request, as this fix will do for its case.

Parent Epic

#36814

Activity

  1. dario-daza commented on Aug 25, 2026

    @dario-daza
    Member

    Adding some independent measurements that corroborate this issue, gathered testing against a large dataset (~718,174 contentlets):

    • Filtering by a specific searchable field (Content Type: File Asset + File Name filter) took ~2 minutes to return a response, versus ~31.5 seconds for the equivalent global search filter term — roughly 3.8x slower, consistent with the field-filter re-scan behavior described here.
    • Combining a secondary-language filter with the global search filter took ~12 seconds to generate a response.
    • A plain global search in Content Drive took ~25 seconds to return results, versus ~24ms for the same term in the Search All portlet.

    These numbers are from a larger dataset than referenced in the issue description, so the relative slowdown compounds further at scale — an additional data point for the "falls within 20% of an equivalent content-search operation" acceptance criterion.

  2. moved this from New to In Review in dotCMS - Product Planningon Aug 27, 2026
  3. self-assigned this
    on Sep 21, 2026
  4. dario-daza commented on Sep 24, 2026

    @dario-daza
    Member

    ✅ QA PASSED

    Tested the fix from #37395 against a large customer-scale dataset (~718k contentlets) on a local stack running trunk (OpenSearch migration phase 2).

    Method: A/B comparison on the same image and data, run in three rounds (B → A → B):

    • A reproduces the pre-fix behavior (BROWSER_SINGLE_PASS_CHUNK_SIZE=900)
    • B is the shipped default (7,000).

    Latencies are medians of 10 runs after a warm-up. Chunk counts come from BrowserAPIImpl debug logs.

    Field filter with sparse / no matches (the case this issue targets)

    Folder size Chunks A → B Median A → B Result
    ~1.8k 3 → 1 0.25s → 0.18s 1.4× faster, single scan
    ~11k 13 → 2 1.83s → 0.42s 4.4× faster
    ~11k (0 matches) 13 → 2 1.65s → 0.42s 3.9× faster
    ~26k (File Asset + File Name) 30 → 4 7.37s → 1.17s 6.3× faster
    ~45k 28 (cut at 10s) → 7 10.2s → 2.9s A returned 0 results (hasMore=true); B complete
    ~68k 15 (cut at 10s) → 10 10.4s → 8.1s A returned 2 of 6; B complete

    Besides the latency gain, the wider chunk avoids hitting the 10s scan budget (BROWSER_DB_MAX_SCAN_TIME_MILLIS) on large folders. Before the fix, those searches returned an empty or partial first page.

    Correctness

    • 14 full result sets (all pages) compared across A and both B rounds: identical, no duplicates, no gaps. They cover Text, Date range, Checkbox (multi-value), Relationship, Relationship + Text, workflow + Text, free text, and free text + field.
    • Pagination: a 2.3k-result set walked over 57 pages resumes correctly within the chunk; total walk time is unchanged (19.3s vs 19.2s).
    • Relationship, workflow and free-text combinations never take the widened path. They stay on the 900-row hybrid / DB path, with the same results in both modes.
    • The clamp works: with BROWSER_DB_MAX_SCAN_ROWS=5000, the chunk size is 5000 and the results are unchanged. No new feature flag is involved.

    Notes / follow-ups (non-blocking)

    Not covered in this run: Tag filters (the dataset has no tags), a restricted-user permission check, and the UI payload check in Content Drive.

  5. removed their assignment
    on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions