Skip to content

Commit

Permalink
api: remove materialized views
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Jul 18, 2024
1 parent 964e48d commit b268624
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
18 changes: 10 additions & 8 deletions packages/daimo-api/src/contract/foreignCoinIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export class ForeignCoinIndexer extends Indexer {
const result = await retryBackoff(
`foreignCoinIndexer-logs-query-${from}-${to}`,
async () => {
await Promise.all([
pg.query(`REFRESH MATERIALIZED VIEW filtered_erc20_transfers;`),
pg.query(`REFRESH MATERIALIZED VIEW filtered_eth_transfers;`),
]);
return await pg.query(
`
SELECT * FROM (
Expand All @@ -77,8 +73,11 @@ export class ForeignCoinIndexer extends Indexer {
t,
v,
log_idx as sort_idx
FROM filtered_erc20_transfers
WHERE block_num BETWEEN $1 AND $2
FROM erc20_transfers
WHERE ig_name='erc20_transfers'
AND src_name='base'
AND block_num BETWEEN $1 AND $2
AND ((t in (SELECT addr FROM names)) OR (f in (SELECT addr FROM names)))
UNION ALL
SELECT
chain_id,
Expand All @@ -91,8 +90,11 @@ export class ForeignCoinIndexer extends Indexer {
"to" as t,
"value" as v,
trace_action_idx as sort_idx
FROM filtered_eth_transfers et
WHERE block_num BETWEEN $1 AND $2
FROM eth_transfers et
WHERE ig_name='eth_transfers'
AND src_name='baseTrace'
AND block_num BETWEEN $1 AND $2
AND (("to" in (SELECT addr FROM names)) OR ("from" in (SELECT addr FROM names)))
)
ORDER BY block_num ASC, tx_idx ASC, sort_idx ASC
;`,
Expand Down
26 changes: 1 addition & 25 deletions packages/daimo-api/src/shovel/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Watcher {
// Start from a block before the first Daimo tx on Base and Base Sepolia.
private latest = 5699999;
private slowLatest = 5699999;
private batchSize = 100000;
private batchSize = 25000;
private isIndexing = false;
private isSlowIndexing = false;

Expand Down Expand Up @@ -98,30 +98,6 @@ export class Watcher {
CREATE INDEX IF NOT EXISTS i_eth_from ON eth_transfers("from");
CREATE INDEX IF NOT EXISTS i_eth_to ON eth_transfers("to");
`);

console.log(`[SHOVEL] migrateDB: filtered_erc20_transfers...`);
await this.pg.query(`
CREATE MATERIALIZED VIEW IF NOT EXISTS filtered_erc20_transfers AS (
SELECT et.*
FROM erc20_transfers et
JOIN names n ON n.addr = et.f
OR n.addr = et.t
);
CREATE INDEX IF NOT EXISTS i_block_num
ON filtered_erc20_transfers (block_num);
`);

console.log(`[SHOVEL] migrateDB: filtered_eth_transfers...`);
await this.pg.query(`
CREATE MATERIALIZED VIEW IF NOT EXISTS filtered_eth_transfers AS (
SELECT et.*
FROM eth_transfers et
JOIN names n ON n.addr = et.to
OR n.addr = et.from
);
CREATE INDEX IF NOT EXISTS i_filtered_eth_transfers_block_num
ON filtered_eth_transfers (block_num);
`);
}

async init() {
Expand Down

0 comments on commit b268624

Please sign in to comment.