Skip to content

feat: allow passing historical as a parameter #313

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

Conversation

edisontim
Copy link
Contributor

@edisontim edisontim commented Nov 7, 2024

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

  • New Features
    • Enhanced event synchronization methods to support fetching and subscribing to historical events.
    • Added a historical parameter to key functions, allowing users to specify whether to include historical events in their queries.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request involve the modification of three functions—getSyncEvents, getEvents, and syncEvents—in the packages/state/src/recs/index.ts file. A new parameter, historical, has been added to each function, defaulting to true. This parameter allows the functions to determine whether to fetch and subscribe to historical events, enhancing their functionality without altering existing logging behavior.

Changes

File Change Summary
packages/state/src/recs/index.ts Updated method signatures for getSyncEvents, getEvents, and syncEvents to include a new parameter historical (default: true).

Poem

In the code where events align,
A new parameter makes it fine.
Historical tales now come to play,
Fetching memories from yesterday.
With a hop and a skip, we enhance the flow,
Celebrating changes, watch our features grow! 🐇✨


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 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.

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (2)
packages/state/src/recs/index.ts (2)

161-161: Consider enhancing the historical parameter documentation.

While the documentation is accurate, it would be more helpful to explain what happens when historical is set to false. This would help developers understand the implications of this parameter choice.

Consider expanding the documentation like this:

-@param historical - Whether to fetch historical events (default: true).
+@param historical - Whether to fetch historical events (default: true). When set to false, only new events will be fetched, ignoring any events that occurred before the function call.

304-304: Consider enhancing the historical parameter documentation for subscription context.

The documentation should clarify how this parameter affects event subscription behavior.

Consider expanding the documentation like this:

-@param historical - Whether to sync to historical events (default: true).
+@param historical - Whether to sync to historical events (default: true). When true, the subscription will receive both historical events and new events as they occur. When false, only new events occurring after subscription creation will be received.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1b7e2 and a2e0cef.

📒 Files selected for processing (1)
  • packages/state/src/recs/index.ts (6 hunks)
🔇 Additional comments (3)
packages/state/src/recs/index.ts (3)

66-66: LGTM: Documentation for historical parameter is clear and complete.

The added JSDoc documentation for the historical parameter clearly explains its purpose and default value.


93-104: LGTM: Implementation correctly propagates the historical parameter.

The changes maintain consistency by passing the historical parameter to both downstream functions.


168-169: LGTM: Implementation correctly uses the historical parameter.

The changes properly integrate with the client's API. However, let's verify the client's implementation supports this parameter.

Also applies to: 183-183

✅ Verification successful

Based on the search results from previous scripts, we can see that:

  1. getEventMessages is used throughout the codebase, particularly in packages/sdk/src/getEventMessages.ts where it's called with a historical parameter
  2. The client interface is imported from @dojoengine/torii-client package which is an external dependency
  3. The method is consistently used with the historical parameter across different parts of the codebase

Since the ToriiClient interface is defined in an external package and we can see consistent usage of getEventMessages with the historical parameter throughout the codebase, including direct calls to client.getEventMessages(toriiQuery, true), this provides sufficient evidence that the parameter is supported.

Implementation verified: The historical parameter is supported by ToriiClient

The codebase shows consistent usage of the historical parameter with getEventMessages, and the parameter is properly passed through to the client's API call.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ToriiClient's getEventMessages method supports the historical parameter
# Test: Search for the getEventMessages method definition
ast-grep --pattern 'interface ToriiClient {
  $$$
  getEventMessages($_): $_
  $$$
}'

Length of output: 92


Script:

#!/bin/bash
# Let's try a broader search for ToriiClient and its method definitions
rg -A 10 "ToriiClient" 

Length of output: 17270


Script:

#!/bin/bash
# Also search for getEventMessages implementation
rg -A 5 "getEventMessages"

Length of output: 2922


Script:

#!/bin/bash
# Search for any interface or class containing getEventMessages
ast-grep --pattern '(interface|class) $_ {
  $$$
  getEventMessages($_) {
    $$$
  }
  $$$
}'

Length of output: 96


Script:

#!/bin/bash
# Let's search for the ToriiClient interface definition in the torii-client package
rg -A 10 "export (type|interface) ToriiClient"

# Also search for any TypeScript interface containing getEventMessages
ast-grep --pattern 'interface $_ {
  $$$
  getEventMessages($_): $_
  $$$
}'

Length of output: 127

Comment on lines +93 to +94
logging: boolean = false,
historical: boolean = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Tests needed for the new historical parameter functionality.

While the implementation looks good, tests should be added to verify the behavior of the historical parameter across all modified functions. This should include:

  1. Test cases with historical=true (default behavior)
  2. Test cases with historical=false (new behavior)
  3. Integration tests showing the interaction between these functions

Would you like me to help create test cases for these scenarios?

Also applies to: 168-169, 315-316

Comment on lines +315 to +316
logging: boolean = false,
historical: boolean = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Verification needed: Historical parameter implementation mismatch

The implementation shows inconsistency in how the historical parameter is used:

  • In packages/state/src/recs/index.ts, it's properly passed as a parameter
  • In packages/sdk/src/subscribeEventQuery.ts, it's hardcoded to true

This suggests potential issues:

  • The SDK's implementation doesn't expose the historical parameter to users
  • The hardcoded value might conflict with the configurable parameter in the state package
🔗 Analysis chain

LGTM: Implementation correctly uses the historical parameter.

The changes properly integrate with the client's API. However, let's verify the client's implementation supports this parameter.

Also applies to: 321-321

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ToriiClient's onEventMessageUpdated method supports the historical parameter
# Test: Search for the onEventMessageUpdated method definition
ast-grep --pattern 'interface ToriiClient {
  $$$
  onEventMessageUpdated($_): $_
  $$$
}'

Length of output: 92


Script:

#!/bin/bash
# Let's try a broader search for ToriiClient and onEventMessageUpdated
# First, find relevant files
fd -t f -e ts -e tsx ToriiClient

# Then search for onEventMessageUpdated method/function definitions
rg -l "onEventMessageUpdated" 

# Finally, let's look for actual implementations or interface definitions
ast-grep --pattern 'onEventMessageUpdated($_)'

Length of output: 186


Script:

#!/bin/bash
# Let's examine the actual implementation and usage in both files
rg -A 5 -B 5 "onEventMessageUpdated" packages/sdk/src/subscribeEventQuery.ts packages/state/src/recs/index.ts

Length of output: 1657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants