Skip to content

Commit

Permalink
Always use transfers_block_num for transfers by default (#36)
Browse files Browse the repository at this point in the history
When querying with no parameters, the default is to query `transfer_events`.
However since the `ORDER BY` clause specify the `block_number` it will slow
down the query significantly.

Changing the default to always use the `transfers_block_num` MV table helps
solve the issue.
  • Loading branch information
0237h authored May 30, 2024
1 parent 8fc6cf4 commit aab2b63
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use
query += `SELECT * FROM `;

const q = query_params as ValidUserParams<typeof endpoint>;
if (q.block_range) {
query += `transfers_block_num `;
} else if (q.from) {
if (q.from) {
query += `transfers_from `;
} else if (q.to) {
query += `transfers_to `;
} else if (q.contract || q.symcode) {
query += `transfers_contract `;
} else {
query += `transfer_events `;
query += `transfers_block_num `;
}

// FINAL increases ClickHouse query response time significantly when lots of data needs merging
Expand Down

0 comments on commit aab2b63

Please sign in to comment.