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

fix: logging #360

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

fix: logging #360

wants to merge 3 commits into from

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Dec 15, 2024

  • reduces loggin

Summary by CodeRabbit

  • New Features

    • Introduced an ordering parameter for fetching event messages, entities, and events, enhancing data retrieval flexibility.
  • Bug Fixes

    • Improved logging behavior across various functions to control verbosity based on parameters.
  • Tests

    • Expanded test coverage for the convertValues function, particularly for large numbers and complex data structures.
  • Chores

    • Updated subproject commit hash to reflect the latest version.

Copy link

coderabbitai bot commented Dec 15, 2024

Walkthrough

The pull request introduces enhancements to data fetching and logging functionality across multiple files in the Dojo SDK. The primary changes include adding orderBy and entityModels parameters to various functions in the SDK, enabling more flexible data retrieval with custom ordering. Additionally, logging mechanisms have been refined to provide more granular control over console output. The modifications span the SDK's event message retrieval, state management, and testing utilities, focusing on improving query capabilities and logging precision.

Changes

File Change Summary
packages/sdk/src/getEventMessages.ts Added orderBy parameter to function signature, updated toriiQuery to support ordering
packages/state/src/recs/index.ts Updated getSyncEntities, getSyncEvents, getEntities, and getEvents functions with orderBy and entityModels parameters, refined logging conditions
packages/state/src/__tests__/utils.test.ts Enhanced test coverage for convertValues function, added tests for large numbers, arrays, and complex type conversions
worlds/dojo-starter Subproject commit hash updated

Sequence Diagram

sequenceDiagram
    participant Client
    participant SDK
    participant ToriiClient
    
    Client->>SDK: getEventMessages(params, orderBy)
    SDK->>ToriiClient: Query with ordering
    ToriiClient-->>SDK: Return ordered results
    SDK-->>Client: Filtered and ordered messages
Loading

Possibly related PRs

Poem

🐰 Hop, hop, through the code we go,
Ordering messages with a rabbit's flow
Parameters dance, logs shine bright
Flexibility leaps with pure delight!
SDK magic, clean and neat 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98887be and b3944cd.

📒 Files selected for processing (3)
  • packages/sdk/src/getEventMessages.ts (1 hunks)
  • packages/state/src/__tests__/utils.test.ts (1 hunks)
  • packages/state/src/recs/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/state/src/tests/utils.test.ts
  • packages/sdk/src/getEventMessages.ts
  • packages/state/src/recs/index.ts

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.

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: 3

🔭 Outside diff range comments (2)
packages/sdk/src/getEventMessages.ts (1)

Line range hint 60-61: Consider reducing logging verbosity.

Given the PR's objective to reduce logging, consider:

  1. Removing or condensing the detailed entity logging at offset
  2. Limiting the error logging to essential information
  3. Removing the final log of all entities, as it duplicates information
- if (options?.logging) {
-     console.log(`Fetched entities at offset ${cursor}:`, entities);
- }

  if (options?.logging) {
-     console.error("Error fetching entities:", error);
+     console.error("Error fetching entities");
  }

- if (options?.logging) {
-     console.log("All fetched entities:", allEntities);
- }

Also applies to: 77-79, 86-88

packages/sdk/src/index.ts (1)

Line range hint 153-155: Reduce error logging verbosity.

In line with the PR's objective to reduce logging, consider simplifying the error message to exclude the full error object.

- console.error("Failed to send message:", error);
+ console.error("Failed to send message");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a357d4 and 98887be.

📒 Files selected for processing (5)
  • packages/sdk/src/getEventMessages.ts (1 hunks)
  • packages/sdk/src/index.ts (2 hunks)
  • packages/state/src/__tests__/utils.test.ts (1 hunks)
  • packages/state/src/recs/index.ts (4 hunks)
  • worlds/dojo-starter (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • worlds/dojo-starter
🔇 Additional comments (4)
packages/sdk/src/getEventMessages.ts (1)

53-53: Verify the purpose of empty order_by array.

The addition of an empty order_by array seems unrelated to the PR's objective of reducing logging. Please clarify the purpose of this change.

✅ Verification successful

The empty order_by array is consistent with the codebase pattern

The addition of order_by: [] in getEventMessages.ts aligns with the existing pattern in the codebase, where all getEntities and similar query calls include this parameter. This change appears to be a consistency improvement rather than being related to logging reduction.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other usages of order_by to understand the context
rg "order_by" --type ts

Length of output: 263


Script:

#!/bin/bash
# Get more context around the order_by usage in both files
rg "order_by" -B 5 -A 5 --type ts

Length of output: 2698

packages/state/src/__tests__/utils.test.ts (1)

211-213: LGTM! Removal of console.warn test aligns with logging reduction goal.

The commented-out test expectation for console.warn is consistent with the PR's objective to reduce logging in the codebase.

packages/state/src/recs/index.ts (2)

145-145: LGTM: Improved logging control

The change properly gates logging behind the logging flag, aligning with the PR objective to reduce logging.


142-142: Verify client implementation of order_by parameter

Let's verify if the Torii client properly implements the order_by functionality.

@@ -135,7 +135,7 @@ export async function init<T extends SchemaType>(
sendMessage: async (
data: TypedData,
account: Account,
isSessionSignature: boolean = false
_isSessionSignature: boolean = false
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider removing unused parameter.

The underscore prefix in _isSessionSignature suggests this parameter is unused. If it's no longer needed, consider removing it entirely.

- _isSessionSignature: boolean = false

@@ -139,9 +139,10 @@ export const getEntities = async <S extends Schema>(
offset,
clause,
dont_include_hashed_keys: false,
order_by: [],
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving type safety and documentation for the order_by parameter

The newly added order_by parameter has several concerns:

  1. Using any[] reduces type safety. Consider defining a proper type for the ordering criteria.
  2. The parameter is not documented in the function's JSDoc.
  3. An empty array default value might not provide value if not implemented in the underlying client.

Consider defining a proper type and updating the documentation:

// Define a type for the ordering criteria
type OrderBy = {
  field: string;
  direction: 'asc' | 'desc';
};

// Update the function signature and documentation
/**
 * @param order_by - Optional array of ordering criteria for the results
 */
export const getEntities = async <S extends Schema>(
  // ... other params ...
  order_by: OrderBy[] = []
) => {

Also applies to: 189-189, 261-261

Comment on lines +420 to +423
if (logging)
console.warn(
`Component ${componentName} not found in provided components.`
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider gating critical warning messages

While the change aligns with reducing logging, missing components might indicate a critical issue that developers should always be aware of. Consider keeping this warning unconditional or using a different logging level (error) that's always enabled.

Consider reverting this change or using error logging:

-                if (logging)
-                    console.warn(
-                        `Component ${componentName} not found in provided components.`
-                    );
+                console.error(
+                    `Component ${componentName} not found in provided components.`
+                );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (logging)
console.warn(
`Component ${componentName} not found in provided components.`
);
console.error(
`Component ${componentName} not found in provided components.`
);

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.

1 participant