-
Notifications
You must be signed in to change notification settings - Fork 159
fix: cache getAcceptsAddresses #431
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
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| END)::int AS new_sellers | ||
| FROM filtered_transfers ft | ||
| LEFT JOIN seller_first_transactions sft ON ft.recipient = sft.recipient | ||
| LEFT JOIN recipient_first_transaction rft ON ft.recipient = rft.recipient |
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 code references a materialized view recipient_first_transaction that doesn't exist in the database, causing this query to fail at runtime.
View Details
📝 Patch Details
diff --git a/packages/internal/databases/transfers/prisma/migrations/20260105000000_recipient_first_transaction/migration.sql b/packages/internal/databases/transfers/prisma/migrations/20260105000000_recipient_first_transaction/migration.sql
new file mode 100644
index 00000000..45829f39
--- /dev/null
+++ b/packages/internal/databases/transfers/prisma/migrations/20260105000000_recipient_first_transaction/migration.sql
@@ -0,0 +1,11 @@
+-- CreateMaterializedView
+CREATE MATERIALIZED VIEW recipient_first_transaction AS
+SELECT
+ recipient,
+ MIN(block_timestamp) AS first_transaction_date
+FROM "TransferEvent"
+GROUP BY recipient;
+
+-- CreateIndex
+CREATE UNIQUE INDEX recipient_first_transaction_idx
+ON recipient_first_transaction (recipient);
Analysis
Missing materialized view recipient_first_transaction causes SQL runtime error
What fails: Queries in getOverallSellerStatistics() and getBucketedSellerStatistics() fail at runtime when executing the SQL that references the undefined materialized view recipient_first_transaction.
How to reproduce:
- Call the
/trpc/sellers.getOverallSellerStatisticsendpoint (orgetOverallSellerStatistics()directly) - The query attempts to execute a LEFT JOIN against
recipient_first_transaction
Result: PostgreSQL throws error: relation "recipient_first_transaction" does not exist
Expected behavior: The materialized view should exist and be queryable. This view was referenced in the refactoring commit (2eb749c) but was never created in a migration.
Root cause: Commit 2eb749c5 ("use MV for first txs") refactored the code to replace the inline CTE seller_first_transactions with a LEFT JOIN to recipient_first_transaction, but the corresponding migration file to create this materialized view was never added.
Fix: Added migration 20260105000000_recipient_first_transaction that creates the materialized view with the schema expected by the queries:
CREATE MATERIALIZED VIEW recipient_first_transaction AS
SELECT
recipient,
MIN(block_timestamp) AS first_transaction_date
FROM "TransferEvent"
GROUP BY recipient;This allows the statistics queries to efficiently look up each recipient's first transaction date without scanning the entire hypertable for every query.
| END)::int AS new_sellers | ||
| FROM "TransferEvent" t | ||
| LEFT JOIN seller_first_transactions sft ON t.recipient = sft.recipient | ||
| LEFT JOIN recipient_first_transaction rft ON t.recipient = rft.recipient |
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 code references a materialized view recipient_first_transaction that doesn't exist in the database, causing this query to fail at runtime.
View Details
📝 Patch Details
diff --git a/packages/internal/databases/transfers/prisma/migrations/20260105182134_add_recipient_first_transaction_mv/migration.sql b/packages/internal/databases/transfers/prisma/migrations/20260105182134_add_recipient_first_transaction_mv/migration.sql
new file mode 100644
index 00000000..a22f78d6
--- /dev/null
+++ b/packages/internal/databases/transfers/prisma/migrations/20260105182134_add_recipient_first_transaction_mv/migration.sql
@@ -0,0 +1,11 @@
+-- Create materialized view for first transaction date by recipient
+CREATE MATERIALIZED VIEW recipient_first_transaction AS
+SELECT
+ recipient,
+ MIN(block_timestamp) AS first_transaction_date
+FROM "TransferEvent"
+GROUP BY recipient;
+
+-- Create index for fast lookups
+CREATE UNIQUE INDEX recipient_first_transaction_idx
+ON recipient_first_transaction (recipient);
Analysis
Missing materialized view recipient_first_transaction referenced in seller statistics queries
What fails: The seller statistics functions getBucketedSellerStatistics() in apps/scan/src/services/transfers/sellers/stats/bucketed.ts (line 66) and getOverallSellerStatistics() in apps/scan/src/services/transfers/sellers/stats/overall.ts (line 33) reference a materialized view recipient_first_transaction that does not exist in the database, causing runtime SQL errors.
How to reproduce:
1. Call getBucketedSellerStatistics() with any valid input
2. The queryRaw() function executes the SQL query against the transfers database
3. PostgreSQL returns: relation "recipient_first_transaction" does not exist
Result: Runtime error - PostgreSQL cannot execute the query due to missing materialized view
Expected: The materialized view should exist and contain recipient addresses with their first transaction timestamps
Root cause: Commit 2eb749c5 (use MV for first txs) refactored seller statistics from using inline CTE seller_first_transactions to a materialized view recipient_first_transaction, but the corresponding database migration was never created.
Fix: Created migration packages/internal/databases/transfers/prisma/migrations/20260105182134_add_recipient_first_transaction_mv/migration.sql that creates the missing materialized view with proper indexing for query performance.
No description provided.