Repository navigation
refactor: Rip out Router.staticCache - #172
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughRemoved the Router static route cache and all related logic. add, attach, and lookup now operate solely on the unified PathTrie (_allRoutes). No public API signatures changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Router
participant PathTrie as _allRoutes (PathTrie)
rect rgba(230,240,255,0.5)
note right of Router: New flow (no static cache)
Client->>Router: lookup(path)
Router->>PathTrie: find(path)
PathTrie-->>Router: RouteMatch | null
Router-->>Client: result
end
sequenceDiagram
autonumber
participant Client
participant Router
participant StaticCache as Static Cache (removed)
participant PathTrie as _allRoutes (PathTrie)
rect rgba(255,245,230,0.5)
note right of Router: Old flow (with static cache)
Client->>Router: lookup(path)
Router->>StaticCache: get(path)
alt hit
StaticCache-->>Router: RouteMatch
Router-->>Client: result
else miss
Router->>PathTrie: find(path)
PathTrie-->>Router: RouteMatch | null
Router->>StaticCache: put(path, result)
Router-->>Client: result
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks✅ Passed checks (3 passed)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #172 +/- ##
==========================================
- Coverage 91.84% 91.82% -0.03%
==========================================
Files 85 85
Lines 3128 3118 -10
Branches 1620 1616 -4
==========================================
- Hits 2873 2863 -10
Misses 255 255 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f645426 to
e1599f7
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
lib/src/router/router.dart (2)
75-82: Doc comment still references “static first”; clarify post‑cache removal.Now that there’s no separate static cache, make the comment reflect PathTrie matching semantics instead of an implementation detail.
Apply this diff:
- /// The input [path] string is normalized before lookup. Static routes are - /// checked first, followed by dynamic routes in the trie. + /// The input [path] string is normalized before lookup. Matching follows + /// PathTrie semantics (static segments preferred over params/wildcards); + /// no separate static cache is used.
82-96: Add regressions for tail-wildcard/param edge cases.Please add tests that previously triggered the bug:
- Prefer static over wildcard: '/users' vs '/**'.
- Tail wildcard with no params: '/files/**' matched by '/files' and '/files/a/b'.
- Param vs wildcard precedence: '/:id' over '/**' for '/a'.
I can draft test cases if helpful.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/src/router/router.dart(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: nielsenko
PR: serverpod/relic#62
File: lib/src/router/router.dart:31-38
Timestamp: 2025-05-09T07:55:38.627Z
Learning: In the Relic router implementation, attaching a sub-router doesn't require clearing the parent router's static cache because it only adds new routes without affecting existing cache entries. The sub-router's cache is cleared primarily to save memory.
Learnt from: nielsenko
PR: serverpod/relic#62
File: lib/src/router/router.dart:0-0
Timestamp: 2025-05-09T10:11:33.427Z
Learning: In the Router implementation, re-adding a route with the same path isn't currently allowed and will throw an ArgumentError from _allRoutes.add(), but handling cache invalidation or updates proactively is important for future-proofing in case route updates are later supported.
📚 Learning: 2025-05-09T07:55:38.627Z
Learnt from: nielsenko
PR: serverpod/relic#62
File: lib/src/router/router.dart:31-38
Timestamp: 2025-05-09T07:55:38.627Z
Learning: In the Relic router implementation, attaching a sub-router doesn't require clearing the parent router's static cache because it only adds new routes without affecting existing cache entries. The sub-router's cache is cleared primarily to save memory.
Applied to files:
lib/src/router/router.dart
📚 Learning: 2025-05-05T14:40:00.323Z
Learnt from: nielsenko
PR: serverpod/relic#52
File: lib/src/router/router.dart:37-53
Timestamp: 2025-05-05T14:40:00.323Z
Learning: In the Router and PathTrie implementation in Dart, both static and dynamic routes consistently throw ArgumentError when attempting to add duplicate routes, despite comments suggesting dynamic routes would be overwritten with a warning.
Applied to files:
lib/src/router/router.dart
📚 Learning: 2025-05-09T10:11:33.427Z
Learnt from: nielsenko
PR: serverpod/relic#62
File: lib/src/router/router.dart:0-0
Timestamp: 2025-05-09T10:11:33.427Z
Learning: In the Router implementation, re-adding a route with the same path isn't currently allowed and will throw an ArgumentError from _allRoutes.add(), but handling cache invalidation or updates proactively is important for future-proofing in case route updates are later supported.
Applied to files:
lib/src/router/router.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Run Unit Tests (macos-latest, beta, upgrade)
- GitHub Check: Run Unit Tests (macos-latest, beta, downgrade)
- GitHub Check: Run Unit Tests (macos-latest, 3.5.0, downgrade)
- GitHub Check: Run Unit Tests (macos-latest, stable, downgrade)
- GitHub Check: Run Unit Tests (macos-latest, 3.5.0, upgrade)
- GitHub Check: Run Unit Tests (windows-latest, beta, upgrade)
🔇 Additional comments (1)
lib/src/router/router.dart (1)
61-64: LGTM: switching to PathTrie.addOrUpdateInPlace removes the brittle static-cache path.Per‑verb duplicate protection is preserved via _RouterEntry.add(). Looks good.
|
@CodeRabbit Add issue to re-enable the static route optimization without re-introducing this issue. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll create an issue to track re-enabling the static route optimization. Let me first examine the changes to better understand what was removed. Based on the changes and your request, I'll create an issue to track re-enabling the static route optimization properly. @nielsenko I've created an issue to track re-enabling the static route optimization. The issue references this PR and your request, and has been assigned to you. It outlines the background context and what needs to be done to safely re-implement the optimization that was removed due to the bug. 🏁 Script executed: Length of output: 5748 🏁 Script executed: Length of output: 45 @nielsenko I've successfully created issue #174 to track re-enabling the static route optimization: #174 The issue includes:
The issue is now available for tracking the work to restore the performance benefits of static route caching while ensuring the underlying bug is properly addressed. |
SandPod
left a comment
There was a problem hiding this comment.
Please add a test that validates the bug is no longer present.
|
^ A bit harsh comment. Changes are fine but please add a test that validates the bug no longer exists and ensures we don't run into the same issue again in the future. |
e1599f7 to
731b9f8
Compare
Done |
731b9f8 to
1036bff
Compare
|
Rebased on top of main |
Description
This PR disables an optimization in the
Routerregarding static paths, ie. paths without any dynamic elements (/:id/, /*/, /**).It does so because a bug was identified that caused
LookupResultto contain wrongmatchedandremainingproperties on subsequent lookups in certain cases.Related Issues
Fixes: #173
Pre-Launch Checklist
Please ensure that your PR meets the following requirements before submitting:
///), ensuring consistency with existing project documentation.Breaking Changes
This just disables an internal optimization.
Summary by CodeRabbit