Skip to content

Commit

Permalink
change pkey, add indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroShkvorets committed Dec 18, 2023
1 parent db597c1 commit eebd2f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions antelope.trxstats/schema.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE TABLE
IF NOT EXISTS transactions (
"trx_id" VARCHAR(64) PRIMARY KEY,
"id" VARCHAR(16) PRIMARY KEY,
"trx_id" VARCHAR(64),
"block_num" BIGINT,
"block_time" TIMESTAMP,
"status" INT,
Expand All @@ -9,4 +10,14 @@ CREATE TABLE
"net_usage" INT,
"cpu_usage_micro_seconds" INT,
"net_usage_words" INT
);
);

-- Add indexes
CREATE INDEX
idx_cpu_usage ON transactions ("cpu_usage_micro_seconds");

CREATE INDEX idx_net_usage_words ON transactions ("net_usage_words");

CREATE INDEX idx_action_count ON transactions ("action_count");

CREATE INDEX idx_trx_id ON transactions ("trx_id");
5 changes: 3 additions & 2 deletions antelope.trxstats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ fn map_trxs(block: Block) -> Result<Transactions, Error> {
fn db_out(trxs: Transactions) -> Result<DatabaseChanges, substreams::errors::Error> {
// Initialize changes container
let mut tables = DatabaseChangeTables::new();
trxs.transactions.into_iter().for_each(|trx| {
trxs.transactions.into_iter().enumerate().for_each(|(i, trx)| {
tables
.create_row("transactions", &trx.trx_id)
.create_row("transactions", format!("{}-{}", trx.block_num, i))
.set("trx_id", trx.trx_id)
.set("block_time", trx.block_time.unwrap())
.set("block_num", trx.block_num)
.set("action_count", trx.action_count)
Expand Down

0 comments on commit eebd2f1

Please sign in to comment.