-
Notifications
You must be signed in to change notification settings - Fork 7
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 indexer purchase data #277
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe changes primarily affect the Changes
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
🧹 Outside diff range and nitpick comments (3)
indexer/src/items.ts (3)
Line range hint
168-184
: Ensure consistent initialization of item properties across eventsIn the
EQUIPMENT_CHANGED
event handler, properties likexp
,greatness
,special1
,special2
, andspecial3
are set tonull
. In other handlers such asPURCHASED_ITEMS
, these properties are initialized to0
or1
. This inconsistency can lead to issues if downstream processes expect these properties to be of a specific type (e.g., number). Ensure that item properties are initialized consistently across all event handlers.
Line range hint
90-100
: Handle potential errors when parsing event dataWhen parsing event data in each case, errors might occur due to unexpected data formats or missing fields. Consider adding error handling to manage exceptions thrown by parsing functions like
parsePurchasedItems
orparseEquipmentChanged
to prevent the indexer from crashing.Apply this diff to add try-catch blocks around parsing functions:
-case PURCHASED_ITEMS: { - const { value } = parsePurchasedItems(event.data, 0); +case PURCHASED_ITEMS: { + let value; + try { + ({ value } = parsePurchasedItems(event.data, 0)); + } catch (error) { + console.error("Error parsing PURCHASED_ITEMS event:", error); + return []; + }Repeat similar patterns for other event cases as needed.
Event filter is missing some event keys.
Ensure that the following event keys are included in the filter to prevent missing crucial data during event processing:
DISCOVERED_HEALTH
DISCOVERED_GOLD
DISCOVERED_BEAST
AMBUSHED_BY_BEAST
ATTACKED_BEAST
ATTACKED_BY_BEAST
ADVENTURER_DIED
FLEE_FAILED
FLEE_SUCCEEDED
NEW_HIGH_SCORE
REWARD_DISTRIBUTION
RECEIVED_LEVEL_SEED
NEW_COLLECTION_TOTAL
TRANSFER
CLAIMED_FREE_GAME
🔗 Analysis chain
Line range hint
56-68
: Confirm inclusion of all relevant events in the filterThe
filter
object has been updated to include new events likeDISCOVERED_LOOT
andEQUIPMENT_CHANGED
. Ensure that all events relevant to item updates are included in the filter to prevent missing any crucial data during event processing.Run the following script to list all event keys defined in
./utils/events.ts
and compare them with those included in thefilter
:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: List all event keys and compare with filter inclusion. # Extract event keys from events.ts rg --type ts "export const .* = .*;" utils/events.ts | awk '{print $3}' > all_event_keys.txt # Extract event keys from filter in items.ts rg --type ts "keys: \[.*\]" indexer/src/items.ts | sed 's/.*keys: \[\(.*\)\].*/\1/' | tr ',' '\n' | sed 's/ //g' > filter_event_keys.txt # Compare the two lists echo "Event keys not included in filter:" comm -23 <(sort all_event_keys.txt) <(sort filter_event_keys.txt)Length of output: 4728
Script:
#!/bin/bash # Description: List all event keys and compare with filter inclusion. # Extract event keys from events.ts rg --type ts "export const .* = .*;" utils/events.ts | awk '{print $3}' > all_event_keys.txt if [ $? -ne 0 ]; then echo "Failed to extract event keys from utils/events.ts" exit 1 fi # Extract event keys from filter in items.ts rg --type ts "keys:\s*\[.*\]" indexer/src/items.ts | sed 's/.*keys:\s*\[\(.*\)\].*/\1/' | tr ',' '\n' | sed 's/ //g' > filter_event_keys.txt if [ $? -ne 0 ]; then echo "Failed to extract filter event keys from indexer/src/items.ts" exit 1 fi # Check if comm is available if command -v comm >/dev/null 2>&1; then # Compare the two lists echo "Event keys not included in filter:" comm -23 <(sort all_event_keys.txt) <(sort filter_event_keys.txt) else # Alternative comparison using grep echo "comm command not found. Using grep for comparison." sort all_event_keys.txt > sorted_all_event_keys.txt sort filter_event_keys.txt > sorted_filter_event_keys.txt grep -Fxv -f sorted_filter_event_keys.txt sorted_all_event_keys.txt fiLength of output: 536
Script:
#!/bin/bash # Description: Locate all events.ts files in the repository. # Search for all files named events.ts fd --type f --extension ts 'events.ts' # Alternatively, using rg if fd is not available if ! command -v fd >/dev/null 2>&1; then rg --files -g 'events.ts' fiLength of output: 184
Script:
#!/bin/bash # Description: List all event keys from indexer/src/utils/events.ts and compare with filter inclusion in indexer/src/items.ts. # Extract event keys from indexer/src/utils/events.ts rg --type ts "export const .* = .*;" indexer/src/utils/events.ts | awk '{print $3}' > all_event_keys.txt if [ $? -ne 0 ]; then echo "Failed to extract event keys from indexer/src/utils/events.ts" exit 1 fi # Extract event keys from filter in indexer/src/items.ts rg --type ts "keys:\s*\[.*\]" indexer/src/items.ts | sed 's/.*keys:\s*\[\(.*\)\].*/\1/' | tr ',' '\n' | sed 's/ //g' > filter_event_keys.txt if [ $? -ne 0 ]; then echo "Failed to extract filter event keys from indexer/src/items.ts" exit 1 fi # Compare the two lists using grep to find event keys not included in the filter echo "Event keys not included in filter:" grep -Fxv -f filter_event_keys.txt all_event_keys.txtLength of output: 621
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- indexer/src/items.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
indexer/src/items.ts (2)
Line range hint
320-324
: Potential missing updates to item availability in 'ADVENTURER_UPGRADED' eventIn the
ADVENTURER_UPGRADED
event handler, theisAvailable
property is set tofalse
for items. However, the items associated with the adventurer might need to update other properties such asxp
,greatness
, or specials to reflect the upgrade. Verify if additional updates are required to accurately represent the adventurer's upgraded state.Would you like assistance in determining the necessary updates for the items during an adventurer upgrade?
Line range hint
243-258
: Review the use of 'ownerAddress' and 'purchasedTime' in 'UPGRADES_AVAILABLE' eventIn the
UPGRADES_AVAILABLE
event handler,ownerAddress
is set to0
, andpurchasedTime
is set to0
. In other events, when an item is not owned,ownerAddress
is often set tonull
or omitted, andpurchasedTime
is set tonull
or the current timestamp. SettingownerAddress
to0
might not accurately represent the absence of an owner and could cause confusion or errors in data processing.Run the following script to check how
ownerAddress
andpurchasedTime
are set across different event handlers:
xp: 0, | ||
greatness: 1, | ||
special1: 0, | ||
special2: 0, | ||
special3: 0, | ||
isAvailable: false, |
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.
🛠️ Refactor suggestion
Consider refactoring repeated item initialization into a helper function
The initialization of item properties like xp
, greatness
, special1
, special2
, special3
, and isAvailable
is repeated across multiple event handlers (PURCHASED_ITEMS
, EQUIPMENT_CHANGED
, DISCOVERED_LOOT
). Refactoring this repeated code into a helper function will improve maintainability and reduce potential errors from inconsistent values.
Apply this diff to create a helper function for item initialization:
+function initializeItemProperties(itemId, adventurerId, ownerAddress, equipped, isAvailable) {
+ return {
+ item: checkExistsInt(itemId),
+ adventurerId: checkExistsInt(parseInt(adventurerId)),
+ owner: true,
+ equipped: equipped,
+ tier: gameData.ITEM_TIERS[itemId],
+ slot: gameData.ITEM_SLOTS[itemId],
+ type: gameData.ITEM_TYPES[itemId],
+ ownerAddress: checkExistsInt(BigInt(ownerAddress).toString(16)),
+ xp: 0,
+ greatness: 1,
+ special1: 0,
+ special2: 0,
+ special3: 0,
+ isAvailable: isAvailable,
+ purchasedTime: isAvailable ? null : new Date().toISOString(),
+ timestamp: new Date().toISOString(),
+ };
+}
Then replace the repeated initialization code in event handlers with calls to this function:
-// Existing initialization code in PURCHASED_ITEMS
-{
- item: checkExistsInt(item.item.id),
- adventurerId: checkExistsInt(parseInt(as.adventurerId)),
- owner: true,
- equipped: false,
- tier: gameData.ITEM_TIERS[item.item.id],
- slot: gameData.ITEM_SLOTS[item.item.id],
- type: gameData.ITEM_TYPES[item.item.id],
- ownerAddress: checkExistsInt(BigInt(as.owner).toString(16)),
- xp: 0,
- greatness: 1,
- special1: 0,
- special2: 0,
- special3: 0,
- isAvailable: false,
- purchasedTime: new Date().toISOString(),
- timestamp: new Date().toISOString(),
-},
+// Refactored code using the helper function
+initializeItemProperties(
+ item.item.id,
+ as.adventurerId,
+ as.owner,
+ false,
+ false
+),
Committable suggestion was skipped due to low confidence.
Bug presented where a double G20 upgrade presents a market larger than the one produced from VRF.
To fix, the indexer should always store the xp, greatness and special data when an item is purchased and not solely rely on the UpgradesAvailable market data.
Summary by CodeRabbit
DISCOVERED_LOOT
andEQUIPMENT_CHANGED
.UPGRADES_AVAILABLE
case for correct item processing.