Skip to content

chore: Simplify contract subscription indexes #863

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

Closed
wants to merge 1 commit into from

Conversation

arcoraven
Copy link
Contributor

@arcoraven arcoraven commented Mar 10, 2025

Goal: make insert/deletes more performant

  • Remove unused indexes -- each insert was updating all indexes
  • Add chain+blockNumber to the uniqueness constraint to trade off better pruning of the search space for more disk space used

PR-Codex overview

This PR focuses on updating the primary keys and indexes for the contract_event_logs and contract_transaction_receipts models in the Prisma schema, enhancing the database structure for better performance and data integrity.

Detailed summary

  • Updated primary key for contract_event_logs to include chainId, blockNumber, transactionHash, and logIndex.
  • Updated primary key for contract_transaction_receipts to include chainId, blockNumber, and transactionHash.
  • Modified indexes for both models to include chainId and contractAddress.
  • Added SQL migration commands to drop old indexes and create new ones reflecting the schema changes.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@arcoraven arcoraven requested a review from d4mr March 10, 2025 04:05
Copy link

zeet-co bot commented Mar 10, 2025

We're building your pull request over on Zeet.
Click me for more info about your build and deployment.
Once built, this branch can be tested at: https://tw-unreal-demo-engine-vwn0-ph-upd-259a49.engine-aws-usw2.zeet.app before merging 😉

Copy link

zeet-co bot commented Mar 10, 2025

engine-cloud - engine-cloud-dev

We're building your pull request over Zeet. We have provided links for Zeet apps linked to this github repo

Application Name Dashboard Link Preview Link
engine-cloud-core-dev Go to App in Zeet Console Preview App
engine-v3-test-instance Go to App in Zeet Console Preview App

@arcoraven arcoraven requested a review from jakeloo March 10, 2025 04:05
@@index([contractId, timestamp])
@@index([contractId, blockNumber])
@@id([chainId, blockNumber, transactionHash])
@@index([timestamp, chainId, contractAddress])
Copy link
Member

Choose a reason for hiding this comment

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

What is the query pattern?
I believe we always queried by chainId and contractAddress and sometimes with timestamp? If that's the case, timestamp should be at the right-most column?

@@index([topic2])
@@index([topic3])
@@id([chainId, blockNumber, transactionHash, logIndex])
@@index([timestamp, chainId, contractAddress])
Copy link
Member

Choose a reason for hiding this comment

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

How are we querying the data? Did a quick scan, it seems like we don't always pass in a timestamp. In that case we'd probably want to start with chainId, contractAddress - then timestamp or blockNumber

Copy link

This PR is stale because it has been open for 7 days with no activity. Remove stale label or comment or this PR will be closed in 3 days.

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

Successfully merging this pull request may close these issues.

3 participants