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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Warnings:

- The primary key for the `contract_event_logs` table will be changed. If it partially fails, the table could be left without primary key constraint.

*/
-- DropIndex
DROP INDEX "contract_event_logs_blockNumber_idx";

-- DropIndex
DROP INDEX "contract_event_logs_contractAddress_idx";

-- DropIndex
DROP INDEX "contract_event_logs_timestamp_idx";

-- DropIndex
DROP INDEX "contract_event_logs_topic0_idx";

-- DropIndex
DROP INDEX "contract_event_logs_topic1_idx";

-- DropIndex
DROP INDEX "contract_event_logs_topic2_idx";

-- DropIndex
DROP INDEX "contract_event_logs_topic3_idx";

-- DropIndex
DROP INDEX "contract_transaction_receipts_chainId_transactionHash_key";

-- DropIndex
DROP INDEX "contract_transaction_receipts_contractId_blockNumber_idx";

-- DropIndex
DROP INDEX "contract_transaction_receipts_contractId_timestamp_idx";

-- AlterTable
ALTER TABLE "contract_event_logs" DROP CONSTRAINT "contract_event_logs_pkey",
ADD CONSTRAINT "contract_event_logs_pkey" PRIMARY KEY ("chainId", "blockNumber", "transactionHash", "logIndex");

-- AlterTable
ALTER TABLE "contract_transaction_receipts" ADD CONSTRAINT "contract_transaction_receipts_pkey" PRIMARY KEY ("chainId", "blockNumber", "transactionHash");

-- CreateIndex
CREATE INDEX "contract_event_logs_timestamp_chainId_contractAddress_idx" ON "contract_event_logs"("timestamp", "chainId", "contractAddress");

-- CreateIndex
CREATE INDEX "contract_transaction_receipts_timestamp_chainId_contractAdd_idx" ON "contract_transaction_receipts"("timestamp", "chainId", "contractAddress");
15 changes: 4 additions & 11 deletions src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,8 @@ model ContractEventLogs {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@id([transactionHash, logIndex])
@@index([timestamp])
@@index([blockNumber])
@@index([contractAddress])
@@index([topic0])
@@index([topic1])
@@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

@@map("contract_event_logs")
}

Expand Down Expand Up @@ -331,9 +325,8 @@ model ContractTransactionReceipts {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([chainId, transactionHash])
@@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?

@@map("contract_transaction_receipts")
}

Expand Down
Loading