-
Notifications
You must be signed in to change notification settings - Fork 11
indexer: fix bound checks in getDrizzleCursor #109
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
📝 WalkthroughWalkthroughA new JSON file for the Changes
Possibly related PRs
Poem
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 (
|
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- change/@apibara-indexer-2ad98856-798e-4946-8109-02388d49f0e4.json (1 hunks)
- packages/indexer/src/sinks/drizzle/drizzle.test.ts (1 hunks)
- packages/indexer/src/sinks/drizzle/utils.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- change/@apibara-indexer-2ad98856-798e-4946-8109-02388d49f0e4.json
🧰 Additional context used
🔇 Additional comments (4)
packages/indexer/src/sinks/drizzle/drizzle.test.ts (2)
16-18: LGTM: New imports are correctly added and used.The new import statements for
Int8Range,drizzleSink,getDrizzleCursor, andpgTableare correctly added and used throughout the test cases. These changes align with the modifications mentioned in the AI-generated summary and don't introduce any apparent issues.
16-18: Overall assessment: Changes look good, part of a larger refactoring.The modifications to this file are limited to new import statements, which appear to be part of a larger refactoring effort to improve code organization. The existing test cases remain unchanged and correctly use the newly imported functions and types. These changes maintain the existing functionality while potentially improving the overall project structure.
To ensure the refactoring has been applied consistently across the project, consider:
- Reviewing other files that might have been affected by this refactoring.
- Running the entire test suite to confirm that all tests still pass.
- Updating any relevant documentation to reflect the new project structure.
packages/indexer/src/sinks/drizzle/utils.ts (2)
86-89: Improved clarity with explicitundefinedchecksBy explicitly checking for
undefined, the code correctly handles cases wherelowerorupperare0, ensuring that zero is treated as a valid boundary value and not mistakenly considered falsy.
Line range hint
91-95: Potential loss of precision when convertingbiginttoNumberConverting
bigintvalues toNumberusingNumber(lower)andNumber(upper)may lead to loss of precision for values exceedingNumber.MAX_SAFE_INTEGER. This could result in incorrect cursor ranges when dealing with large integers.Please verify whether cursor values could exceed the safe integer range for JavaScript numbers. If so, consider handling
bigintvalues appropriately to avoid precision loss.
| import type { Int8Range } from "./Int8Range"; | ||
| import { drizzle as drizzleSink } from "./drizzle"; | ||
| import { getDrizzleCursor, pgTable } from "./utils"; |
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.
💡 Codebase verification
Incomplete Refactoring: Old Import References Detected
The refactoring appears to be incomplete as there are still references to the old import locations in several files:
packages/indexer/src/sinks/drizzle/utils.tspackages/indexer/src/sinks/drizzle/drizzle.test.tspackages/indexer/src/sinks/drizzle/index.tspackages/indexer/src/sinks/drizzle/insert.ts
Please update these references to use the new import paths and ensure that all tests pass with the updated structure.
🔗 Analysis chain
Verify the refactoring impact on other parts of the codebase.
The new imports suggest a refactoring of the project structure, moving some functionality to separate files. While the changes in this file look good and all tests seem to be using the new imports correctly, it's important to ensure that this refactoring hasn't negatively impacted other parts of the codebase.
To verify the impact of these changes, you can run the following script:
This script will help identify any missed import updates, confirm the existence of the new utility files, and verify that all tests still pass with the new changes.
[/run_scripts]
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining references to the old import locations
# Search for any remaining references to the old import locations
echo "Searching for old import references:"
rg -n 'from "\./Int8Range"' --type ts
rg -n 'from "\./drizzle"' --type ts
rg -n 'getDrizzleCursor|pgTable.*from "\./' --type ts
# Check if the new utility files exist
echo "Checking for new utility files:"
ls -l ./Int8Range.ts ./drizzle.ts ./utils.ts
# Run the test suite to ensure all tests pass with the new changes
echo "Running test suite:"
npm test
Length of output: 2124
Script:
#!/bin/bash
# Description: Re-verify the existence of new utility files in the correct directory
# Define the base directory based on the initial file location
BASE_DIR="packages/indexer/src/sinks/drizzle"
# Check if the new utility files exist in the expected directory
echo "Checking for new utility files in ${BASE_DIR}:"
ls -l ${BASE_DIR}/Int8Range.ts ${BASE_DIR}/drizzle.ts ${BASE_DIR}/utils.ts
# Search for any remaining references to the old import locations within the correct directory
echo "Searching for old import references in ${BASE_DIR}:"
rg -n 'from "\./Int8Range"' --type ts ${BASE_DIR}
rg -n 'from "\./drizzle"' --type ts ${BASE_DIR}
rg -n 'getDrizzleCursor|pgTable.*from "\./' --type ts ${BASE_DIR}
Length of output: 2499
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.
The new code is better
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.
@fracek, understood. Let me know if I can assist further.
🐰😢
✏️ Learnings added
Learnt from: fracek
PR: apibara/typescript-sdk#109
File: packages/indexer/src/sinks/drizzle/drizzle.test.ts:16-18
Timestamp: 2024-10-22T11:16:00.552Z
Learning: In `packages/indexer/src/sinks/drizzle`, the import references are correct and up-to-date according to the new code structure.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
| const [lower, upper] = isArray ? cursor_range : [cursor_range, undefined]; | ||
| let isNoUpperBound = false; | ||
| if (!lower) { | ||
| if (lower === undefined) { |
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.
Wish there was a lint for this
fracek
left a comment
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.
Looks good
No description provided.