-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Fix current block #1170
Fix current block #1170
Conversation
WalkthroughThe update streamlines the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant RuntimeState
participant LoadFunctions
participant RuntimeService
User->>RuntimeState: Request state load
RuntimeState->>LoadFunctions: Call load(prevBlock)
LoadFunctions->>RuntimeState: Preserve timing info
RuntimeState-->>User: State loaded with timing data
User->>RuntimeService: Request broadcast result
RuntimeService->>RuntimeService: Check if block changed
RuntimeService->>RuntimeService: Update clock if necessary
RuntimeService-->>User: Result broadcasted
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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: 2
Outside diff range, codebase verification and nitpick comments (1)
apps/server/src/stores/runtimeState.ts (1)
169-171
: Verify the correctness of the newprevBlock
parameter.The
prevBlock
parameter is not being passed in theload
function calls. Ensure that this parameter is correctly passed and utilized in all instances of theload
function.
apps/server/src/stores/runtimeState.ts
: Lines whereload
is called withoutprevBlock
.Analysis chain
Verify the correctness of the new
prevBlock
parameter.The introduction of the
prevBlock
parameter appears to be correctly handled. Ensure that this parameter is correctly passed and utilized in the function.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type python -A 5 $'load('Length of output: 92
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type ts -A 5 'load('Length of output: 88
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type ts -A 5 'load\('Length of output: 13780
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/server/src/stores/runtimeState.ts (11 hunks)
Additional context used
Learnings (2)
Common learnings
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
apps/server/src/stores/runtimeState.ts (1)
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
Additional comments not posted (4)
apps/server/src/stores/runtimeState.ts (4)
215-220
: Verify the correctness of the newprevBlock
parameter.The introduction of the
prevBlock
parameter appears to be correctly handled. Ensure that this parameter is correctly passed and utilized in the function.Verification successful
The
prevBlock
parameter is correctly utilized in theloadNow
function.The implementation of the
loadNow
function includes appropriate handling of theprevBlock
parameter. Specifically, the code checks ifprevBlock
is defined and if itsid
matches the current block'sid
, then it usesprevBlock.startedAt
to maintain thestartedAt
time.
- File:
apps/server/src/stores/runtimeState.ts
- Lines:
- 236:
if (prevBlock && prevBlock.id === runtimeState.currentBlock.block?.id) {
- 237:
runtimeState.currentBlock.startedAt = prevBlock.startedAt;
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter in `loadNow`. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type python -A 5 $'loadNow('Length of output: 101
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter in `loadNow`. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type typescript -A 5 'loadNow('Length of output: 105
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter in `loadNow`. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type typescript -A 5 'loadNow'Length of output: 70
Script:
#!/bin/bash # Description: Verify the correctness of the new `prevBlock` parameter in `loadNow`. # Test: Search for the function usage. Expect: Correct usage of the new parameter. rg --type ts -A 5 'loadNow'Length of output: 1810
Script:
#!/bin/bash # Description: Verify the implementation of the `loadNow` function for the correct usage of the `prevBlock` parameter. # Test: Search for the `loadNow` function implementation. Expect: Correct usage of the `prevBlock` parameter. ast-grep --lang ts --pattern $'function loadNow($_, $_, $_, $_) { $$$ }'Length of output: 3852
375-377
: Verify the correctness of the updatedloadNow
function usage.The usage of the updated
loadNow
function appears to be correctly handled. Ensure that this function is correctly passed and utilized.
210-211
: Verify the correctness of theloadNext
function usage.The usage of the
loadNext
function appears to be correctly handled. Ensure that this function is correctly passed and utilized.Verification successful
The
loadNext
function is correctly used in the codebase.The function is defined in
apps/server/src/stores/runtimeState.ts
and is utilized in multiple locations, includingRuntimeService.ts
andintegration.controller.ts
. The usage appears to be consistent and correct.
apps/server/src/stores/runtimeState.ts
apps/server/src/services/runtime-service/RuntimeService.ts
apps/server/src/api-integration/integration.controller.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the `loadNext` function usage in `loadNow`. # Test: Search for the function usage. Expect: Correct usage of the function. rg --type python -A 5 $'loadNext('Length of output: 104
Script:
#!/bin/bash # Description: Verify the correctness of the `loadNext` function usage in `loadNow`. # Test: Search for the function usage. Expect: Correct usage of the function. rg --type js -A 5 'loadNext\('Length of output: 32
Script:
#!/bin/bash # Description: Find the definition of the `loadNext` function and trace its usage in the codebase. # Search for the definition of the `loadNext` function rg --type js 'function loadNext' -A 5 # Search for the usage of the `loadNext` function rg --type js 'loadNext' -A 5Length of output: 68
Script:
#!/bin/bash # Description: Search for any occurrence of `loadNext` in the codebase. # Search for any occurrence of `loadNext` rg 'loadNext' -A 5Length of output: 5091
614-617
: Verify the correctness of the newprevBlock
parameter.The introduction of the
prevBlock
parameter appears to be correctly handled. Ensure that this parameter is correctly passed and utilized in the function.
688d76e
to
47de5b2
Compare
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: 6
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/server/src/stores/runtimeState.ts (11 hunks)
Additional context used
Learnings (2)
Common learnings
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
apps/server/src/stores/runtimeState.ts (1)
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
Biome
apps/server/src/stores/runtimeState.ts
[error] 663-663: Unexpected label.
Only loops should be labeled.
The use of labels for other statements is suspicious and unfamiliar.(lint/suspicious/noConfusingLabels)
[error] 663-663: Unused label.
The label is not used by any break statement and continue statement.
Safe fix: Remove the unused label.(lint/correctness/noUnusedLabels)
Additional comments not posted (2)
apps/server/src/stores/runtimeState.ts (2)
169-170
: EnsureruntimeState.currentBlock.block
is not null before accessing itsid
.To prevent potential null reference errors, ensure that
runtimeState.currentBlock.block
is not null before accessing itsid
property.- const prevBlockId = runtimeState.currentBlock.block?.id; - const prevBlockStartAt = runtimeState.currentBlock.startedAt; + const prevBlockId = runtimeState.currentBlock.block ? runtimeState.currentBlock.block.id : undefined; + const prevBlockStartAt = runtimeState.currentBlock.block ? runtimeState.currentBlock.startedAt : null;Skipped due to learnings
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
596-597
: EnsureruntimeState.currentBlock.block
is not null before accessing itsid
.To prevent potential null reference errors, ensure that
runtimeState.currentBlock.block
is not null before accessing itsid
property.- const prevBlockId = runtimeState.currentBlock.block?.id; - const prevBlockStartAt = runtimeState.currentBlock.startedAt; + const prevBlockId = runtimeState.currentBlock.block ? runtimeState.currentBlock.block.id : undefined; + const prevBlockStartAt = runtimeState.currentBlock.block ? runtimeState.currentBlock.startedAt : null;Skipped due to learnings
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- apps/server/src/services/runtime-service/RuntimeService.ts (1 hunks)
- apps/server/src/stores/runtimeState.ts (12 hunks)
- packages/utils/src/rundown-utils/rundownUtils.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- apps/server/src/services/runtime-service/RuntimeService.ts
Additional context used
Learnings (2)
Common learnings
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
apps/server/src/stores/runtimeState.ts (1)
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
Additional comments not posted (7)
packages/utils/src/rundown-utils/rundownUtils.ts (1)
306-320
: Improved variable naming enhances readability.The renaming of
inBlock
tofoundCurrentEvent
clarifies the purpose of the variable, improving the readability of thegetRelevantBlock
function. The logic remains intact.apps/server/src/stores/runtimeState.ts (6)
169-172
: Preserving block state across loads is a good practice.The changes ensure that the current block state is preserved across loads, which is essential for maintaining accurate timing information.
169-172
: Enhanced function signature improves timing management.The addition of the
prevBlock
parameter toloadNow
allows for better management of block timing, improving clarity and functionality.
360-360
: Consistent use of updated functions enhances state management.The integration of
loadNow
andloadBlock
inreloadAll
ensures consistent state management and event loading.
384-384
: Conditional block start time update is efficient.Updating the block start time only when necessary prevents unnecessary state changes, improving efficiency.
597-601
: Streamlined rolling process with accurate state management.Persisting the current block state and using updated functions in
roll
ensures a streamlined process and accurate state management.
659-675
: Correct block state update based on current event.The
loadBlock
function correctly updates the block state based on the current event, ensuring consistency and accuracy.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/server/src/services/runtime-service/RuntimeService.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- apps/server/src/services/runtime-service/RuntimeService.ts
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- apps/server/src/services/runtime-service/RuntimeService.ts (3 hunks)
- apps/server/src/stores/runtimeState.ts (12 hunks)
Files skipped from review as they are similar to previous changes (1)
- apps/server/src/services/runtime-service/RuntimeService.ts
Additional context used
Learnings (2)
Common learnings
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
apps/server/src/stores/runtimeState.ts (1)
Learnt from: cpvalente PR: cpvalente/ontime#1100 File: apps/server/src/stores/runtimeState.ts:195-200 Timestamp: 2024-07-22T18:57:03.714Z Learning: In the `runtimeState.ts` file, ensure that `runtimeState.currentBlock.block` is not null before accessing its `id` property to prevent potential null reference errors.
Additional comments not posted (5)
apps/server/src/stores/runtimeState.ts (5)
169-172
: Verify the persistence logic forcurrentBlock
.The logic to persist the
currentBlock
state across loads by copying it toprevCurrentBlock
seems correct. Ensure this change does not introduce unintended side effects.Verification successful
Persistence logic for
currentBlock
is correctly implemented.The logic to persist the
currentBlock
state across loads by copying it toprevCurrentBlock
and restoring it appears to be correctly implemented. No unintended side effects were identified in the current usage.
- Lines where
currentBlock
is copied and restored:
const prevCurrentBlock = { ...runtimeState.currentBlock };
runtimeState.currentBlock = prevCurrentBlock;
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the persistence logic for `currentBlock` in the `load` function. # Test: Check for any potential side effects introduced by the persistence logic. rg --type-add 'typescript' --type typescript 'runtimeState.currentBlock' -A 5Length of output: 135
Script:
#!/bin/bash # Description: Verify the persistence logic for `currentBlock` in the `load` function. # Test: Check for any potential side effects introduced by the persistence logic. rg 'runtimeState\.currentBlock' -A 5Length of output: 3264
659-675
: Verify the logic in the newloadBlock
function.The
loadBlock
function centralizes block loading logic effectively. Ensure the logic for updatingcurrentBlock
is correct and doesn't introduce errors.Verification successful
The
loadBlock
function logic is correctly implemented.The
loadBlock
function is effectively managing the current block state and is invoked appropriately within the application logic. The function's integration with state management and timers appears correct and does not introduce errors.
- The function is called in contexts that ensure state updates are consistent with application requirements.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the logic in the new `loadBlock` function. # Test: Check for any potential errors introduced by the new logic. rg --type typescript 'loadBlock' -A 5Length of output: 72
Script:
#!/bin/bash # Description: Search for the usage of the `loadBlock` function across the codebase. # Test: Find occurrences of the `loadBlock` function to verify its logic. rg 'loadBlock' -A 10Length of output: 3112
Line range hint
207-207
:
Verify the function signature change forloadNow
.The function signature change to include parameters for the previous block's
id
andstartedAt
values seems appropriate. Ensure all calls toloadNow
are updated to match the new signature.
384-384
: Verify the update logic forcurrentBlock
start time instart
.The logic to update the
currentBlock
start time in thestart
function appears correct. Ensure this update doesn't conflict with other parts of the code.
597-607
: Verify the integration ofloadBlock
in theroll
function.The integration of
loadBlock
in theroll
function seems to improve clarity and efficiency. Ensure this integration is seamless and doesn't introduce errors.
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.
small suggestion, thank you alex!
} | ||
|
||
const shouldUpdateClock = getShouldClockUpdate(RuntimeService.previousClockUpdate, state.clock) || syncBlockStartAt; |
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.
tip: how about having syncBlockStartAt
first? if that is true
, we want dont need to run the function getShouldClockUpdate
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- apps/server/src/services/runtime-service/RuntimeService.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- apps/server/src/services/runtime-service/RuntimeService.ts
No description provided.