Skip to content

fix: restore document query cache matching - #18376

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:go017
Aug 17, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
buua436:go017

Conversation

@buua436

@buua436 buua436 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fixes document query cache matching after the query key factory refactor. Prefix operations previously generated keys with trailing undefined values, causing invalidateQueries and optimistic setQueriesData updates to miss parameterized document list and filter queries.

This PR introduces explicit prefix keys and adds regression tests using TanStack Query’s actual partial matching behavior.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. 🧰 typescript Pull requests that update Typescript code labels Aug 17, 2026
@buua436
buua436 requested a review from wangq8 August 17, 2026 09:35
@buua436 buua436 added the ci Continue Integration label Aug 17, 2026
@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d0f21f8-e83a-4f0a-a604-c99c27fd0675

📥 Commits

Reviewing files that changed from the base of the PR and between 4593d08 and 83db65e.

📒 Files selected for processing (3)
  • web/src/hooks/__tests__/use-document-request-query-keys.test.ts
  • web/src/hooks/document-query-keys.ts
  • web/src/hooks/use-document-request.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change centralizes document query-key factories, re-exports them from the request hook, broadens cache invalidation targets, and adds prefix-matching tests for list and filter keys.

Changes

Document query cache updates

Layer / File(s) Summary
Query-key factories and prefix tests
web/src/hooks/document-query-keys.ts, web/src/hooks/__tests__/use-document-request-query-keys.test.ts
Adds DocumentApiAction and DocumentKeys factories for document lists, filters, thumbnails, and ID lookups. Tests verify list and filter prefix matching.
Request-hook exports
web/src/hooks/use-document-request.ts
Moves DocumentApiAction and DocumentKeys imports and exports to document-query-keys.
Mutation cache invalidation
web/src/hooks/use-document-request.ts
Updates document mutation handlers to invalidate all document queries or all filter queries. Optimistic ingestion state and start-operation behavior remain conditional.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 83db6

This localized cache-key fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Poem

A rabbit checks each query trail,
With tidy keys that never fail.
Lists and filters match by start,
Mutations refresh every part.
“Hop!” says Bun, “the cache is smart!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: restoring document query cache matching.
Description check ✅ Passed The description clearly explains the problem, solution, regression tests, and change type required for this bug fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Thanks for the fix — this correctly addresses the cache-matching regression. I verified the behavior against TanStack Query v5's actual partialMatchKey semantics.

What's correct

  • The root cause is real: DocumentKeys.list() with no args produced ['fetchDocumentList', undefined, undefined, undefined], which never partial-matched the parameterized list key ['fetchDocumentList', searchString, pagination, filter]. Same for filter().
  • Introducing explicit prefix keys (all() → ['fetchDocumentList'], allFilters() → ['fetchDocumentFilter']) is the idiomatic fix.
  • The tests use partialMatchKey(actual, prefix) with the correct argument order and assert the real matching behavior. Good.

Things to consider (non-blocking)

  1. partialMatchKey is an internal API from a transitive dependency. The test imports it directly from @tanstack/query-core, which is not declared in web/package.json (it is a transitive dep of @tanstack/react-query). partialMatchKey is an internal utility, not part of the public API surface. This is fragile — it can break on a minor bump or under stricter resolvers (pnpm/yarn PnP). Consider either declaring @tanstack/query-core explicitly in devDependencies, or (better) asserting through the real QueryClient / invalidateQueries behavior instead of reaching into internals.

  2. all() now also matches byIds. byIds uses ['fetchDocumentList', 'byIds', ids], so invalidateQueries({ queryKey: DocumentKeys.all() }) and setQueriesData({ queryKey: DocumentKeys.all() }) now also target byIds queries (previously the undefined-suffixed key never matched them). This looks like a desirable side effect — e.g. the optimistic run-status updates in useRunDocument now also keep the byIds cache in sync — but please confirm it is intended.

  3. Minor consistency: use-manage-modal.ts:388 still hardcodes queryKey: [DocumentApiAction.FetchDocumentList] instead of DocumentKeys.all(). Optional follow-up to consolidate on the shared factory.

No regressions found in the diff itself; the re-export of DocumentApiAction keeps the existing import in use-manage-modal.ts working.

@wangq8
wangq8 merged commit e96a0a1 into infiniflow:main Aug 17, 2026
19 of 21 checks passed
@wangq8
wangq8 requested review from cike8899 and dcc123456 August 17, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files. 🧪 test Pull requests that update test cases. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants