Skip to content
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

Merged
merged 5 commits into from
Jan 26, 2025
Merged

More batch #1468

merged 5 commits into from
Jan 26, 2025

Conversation

alex-Arc
Copy link
Collaborator

@alex-Arc alex-Arc commented Jan 25, 2025

  • add batching to the client runtime.ts
  • rearrange and explain the update logic RuntimeService.ts
  • fix some strict stuff in RuntimeService.ts
  • fix a issue where the paused state was not properly applied from a restore point in runtimeState.ts

Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This 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

File Change Summary
apps/client/src/common/stores/runtime.ts - Added batchStore to accumulate runtime store updates
- Introduced isUpdatePending to manage update batching
- Modified patchRuntimeProperty to defer state updates
apps/server/src/services/runtime-service/RuntimeService.ts - Added RuntimeStateEventKeys type
- Modified import for RestorePoint
- Restructured broadcastResult decorator logic for more efficient state and event updates
apps/server/src/services/runtime-service/rundownService.utils.ts - Updated getShouldTimerUpdate to accept MaybeNumber for previous value
- Simplified getForceUpdate by removing playbackState parameter
apps/server/src/stores/runtimeState.ts - Extended patchTimer function signature to include RestorePoint
- Added conditional handling for _timer object properties

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@alex-Arc alex-Arc added the priority Issue or PR to be prioritised label Jan 25, 2025
@alex-Arc
Copy link
Collaborator Author

@coderabbitai review

@alex-Arc alex-Arc requested a review from cpvalente January 25, 2025 14:13
Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 booleans hasNewLoaded, justStarted, and hasChangedPlayback are combined under hasImmediateChanges, making the code more concise and understandable. Consider renaming justStarted to isFirstRun for clarity.


697-738: Comprehensive update triggers.
The logic for shouldUpdateTimer, shouldRuntimeUpdate, shouldBlockUpdate, and shouldUpdateClock 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: Handling null in getShouldTimerUpdate.
Skipping updates when currentValue is null is sensible. Consider also logging or clarifying how null 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

📥 Commits

Reviewing files that changed from the base of the PR and between b4caec0 and c7ee3ef.

📒 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 of RestorePoint.
Switching from a type-only import to a value import is appropriate if the code references RestorePoint at runtime. Please make sure to review any references to RestorePoint 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 of RuntimeState 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.
Introducing batchStore and isUpdatePending 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 use patchRuntimeProperty rather than direct store mutations.

apps/server/src/services/runtime-service/rundownService.utils.ts (2)

4-4: Appropriate introduction of MaybeNumber.
This import aligns with functions that now handle null values more gracefully. No immediate issues spotted.


39-39: Simplified getForceUpdate signature.
Removing the playbackState 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

apps/server/src/stores/runtimeState.ts Outdated Show resolved Hide resolved
Copy link
Owner

@cpvalente cpvalente left a 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

@alex-Arc alex-Arc merged commit d34280c into master Jan 26, 2025
4 checks passed
@alex-Arc alex-Arc deleted the more-batch branch January 26, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority Issue or PR to be prioritised
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants