ENG-1785: Cache getAllDiscourseNodes#1067
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@coderabbitai full review |
|
@codex review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis PR implements a versioned cache invalidation system for discourse node types. It introduces a new cache version counter that increments when mutations occur, allowing internal caches in ChangesDiscourse node type cache versioning and invalidation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/roam/src/components/settings/utils/accessors.ts (1)
1149-1214:⚠️ Potential issue | 🟠 Major | ⚡ Quick winInvalidate cache version after migration writes inside
getAllDiscourseNodes.Line 1194 writes migrated block props, but the cache version is not bumped. This can leave
findDiscourseNodeserving stale cached values for the same node UID until another unrelated invalidation happens.Suggested fix
if (retryResult.success) { setBlockProps(pageUid, retryResult.data, false); + invalidateDiscourseNodeTypeCaches(); nodes.push( toDiscourseNode({ ...retryResult.data, type: pageUid, text: nodeText,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/roam/src/components/settings/utils/accessors.ts` around lines 1149 - 1214, In getAllDiscourseNodes, after you call setBlockProps(pageUid, retryResult.data, false) as part of the legacy migration, invalidate the in-memory cache (allDiscourseNodesCache) or bump its version so subsequent calls (and findDiscourseNode) won't return stale data; use getDiscourseNodeTypeCacheVersion() to compute the current version or simply set allDiscourseNodesCache = undefined (or { version: getDiscourseNodeTypeCacheVersion(), nodes: [] }) immediately after the write inside the migrate branch so the function rebuilds the cache with the migrated props on the next access.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/roam/src/components/settings/utils/accessors.ts`:
- Around line 1149-1214: In getAllDiscourseNodes, after you call
setBlockProps(pageUid, retryResult.data, false) as part of the legacy migration,
invalidate the in-memory cache (allDiscourseNodesCache) or bump its version so
subsequent calls (and findDiscourseNode) won't return stale data; use
getDiscourseNodeTypeCacheVersion() to compute the current version or simply set
allDiscourseNodesCache = undefined (or { version:
getDiscourseNodeTypeCacheVersion(), nodes: [] }) immediately after the write
inside the migrate branch so the function rebuilds the cache with the migrated
props on the next access.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2930771e-0bd4-475b-a4fc-addaefb729e6
📒 Files selected for processing (5)
apps/roam/src/components/settings/DiscourseNodeConfigPanel.tsxapps/roam/src/components/settings/utils/accessors.tsapps/roam/src/components/settings/utils/migrateLegacyToBlockProps.tsapps/roam/src/utils/discourseNodeTypeCache.tsapps/roam/src/utils/findDiscourseNode.ts
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
| value: validatedValue, | ||
| }); | ||
|
|
||
| if (key === "Use new settings store") { |
There was a problem hiding this comment.
is this string a const somewhere? If not, it should be. Someone could easily mistype, eg: setting instead of settings
No video because this is a performance bug. I measured the performance using #1055 and we have following improvements before the fix:
Before:
getDiscourseNodes~572ms / 10 callsimageMenu~366ms / 6 callsAfter cache getAllDiscourseNodes:
getDiscourseNodes~80-129ms / 11-12 callsimageMenu~68-122ms / 7 callsSummary by CodeRabbit
Bug Fixes
Chores