-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More batch #1468
More batch #1468
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 WalkthroughThis pull request introduces changes across multiple files in the runtime and service management system. The modifications focus on improving state management, update batching, and type handling. Key changes include implementing a batching mechanism for runtime store updates, refining event handling in the runtime service, adjusting utility functions for timer and playback state, and expanding the flexibility of timer state patching. These updates aim to optimize performance and provide more robust state management capabilities. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
apps/server/src/services/runtime-service/RuntimeService.ts (2)
685-694
: Well-structured big-change checks.
The booleanshasNewLoaded
,justStarted
, andhasChangedPlayback
are combined underhasImmediateChanges
, making the code more concise and understandable. Consider renamingjustStarted
toisFirstRun
for clarity.
697-738
: Comprehensive update triggers.
The logic forshouldUpdateTimer
,shouldRuntimeUpdate
,shouldBlockUpdate
, andshouldUpdateClock
systematically covers most runtime changes. The deep equality checks are valid for moderate state sizes. For very large state, consider more granular checks or partial diffs.apps/client/src/common/stores/runtime.ts (1)
24-33
: Deferred state updates to mitigate flicker.
Accumulating property changes before applying them in one go improves performance. If additional validations are needed (e.g., bounding values), consider doing them immediately on assignment so erroneous updates are not silently batched.apps/server/src/services/runtime-service/rundownService.utils.ts (1)
24-24
: Handlingnull
ingetShouldTimerUpdate
.
Skipping updates whencurrentValue
isnull
is sensible. Consider also logging or clarifying hownull
arises if unexpected in normal operation.apps/server/src/stores/runtimeState.ts (1)
139-139
: Add JSDoc documentation for the patchTimer function.The function handles both public and private state, which should be clearly documented for maintainability.
Add comprehensive documentation:
+/** + * Updates both public timer state and private timer state atomically. + * @param newState - Partial state containing both TimerState and RestorePoint properties + * @remarks + * This function is used for: + * 1. Restoring timer state from a restore point + * 2. Updating timer state during normal operation + * + * The function handles both public properties (TimerState) and private properties (_timer) + * to ensure consistent state restoration. + */ function patchTimer(newState: Partial<TimerState & RestorePoint>) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/client/src/common/stores/runtime.ts
(1 hunks)apps/server/src/services/runtime-service/RuntimeService.ts
(5 hunks)apps/server/src/services/runtime-service/rundownService.utils.ts
(3 hunks)apps/server/src/stores/runtimeState.ts
(1 hunks)
🔇 Additional comments (8)
apps/server/src/services/runtime-service/RuntimeService.ts (4)
24-24
: Consider verifying new usage ofRestorePoint
.
Switching from a type-only import to a value import is appropriate if the code referencesRestorePoint
at runtime. Please make sure to review any references toRestorePoint
in related files to confirm they align with the new import.
39-39
: Good use of narrowed keys.
Limiting keys to'eventNext' | 'eventNow' | 'publicEventNow' | 'publicEventNext'
clarifies which parts ofRuntimeState
this new type handles. This strongly-types the usage of event-specific properties.
185-188
: Logic check for affected events.
These lines cleanly verify whether updated or removed events are currently loaded. This makes it straightforward to decide if the runtime must be reloaded or stopped.
739-764
: Unified state and event updates.
The code updates various aspects of the state (timer
,runtime
,currentBlock
, clock, events) in a single pass, followed by a restore state save if needed. This consolidated approach helps ensure consistency. However, if further expansions are planned, consider extracting these updates into smaller functions to reduce complexity.Also applies to: 771-799
apps/client/src/common/stores/runtime.ts (1)
17-19
: Batch variables for UI updates.
IntroducingbatchStore
andisUpdatePending
is a solid way to buffer rapid updates, reducing potential flicker or excessive renders. Ensure the batching strategy is well-documented so contributors know to usepatchRuntimeProperty
rather than direct store mutations.apps/server/src/services/runtime-service/rundownService.utils.ts (2)
4-4
: Appropriate introduction ofMaybeNumber
.
This import aligns with functions that now handlenull
values more gracefully. No immediate issues spotted.
39-39
: SimplifiedgetForceUpdate
signature.
Removing theplaybackState
parameter keeps the function focused on clock deltas. Ensure any old references to the deprecated parameter are updated and that the new logic aligns with all call sites.apps/server/src/stores/runtimeState.ts (1)
139-146
: Verify state restoration edge cases.The enhanced type safety is good, but we should verify that all state restoration scenarios work correctly, especially with the new
_timer
property handling.Let's verify the state restoration flow:
✅ Verification successful
State restoration implementation is robust and handles edge cases properly
The code demonstrates thorough handling of state transitions, proper type safety, and consistent state management across all scenarios including negative times, force finish, and roll states. No issues found in the state restoration flow.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for all usages of patchTimer to ensure consistent state handling echo "Searching for patchTimer usages..." rg -B 2 -A 2 "patchTimer\(" # Search for RestorePoint type usage to verify type consistency echo "Verifying RestorePoint type usage..." ast-grep --pattern 'type RestorePoint = { $$$ }' # Search for potential timer state mutations echo "Checking for direct timer state mutations..." rg -B 2 -A 2 "runtimeState\.timer\."Length of output: 17587
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left some small suggestions for comments. Looks good otherwise
runtime.ts
RuntimeService.ts
RuntimeService.ts
runtimeState.ts