Skip to content

Commit

Permalink
Fix getter
Browse files Browse the repository at this point in the history
  • Loading branch information
eabz committed Feb 28, 2023
1 parent 979f6cc commit 1c7fa44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 9 additions & 4 deletions bin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ async fn main() {
}

if !config.reset {
let mut indexed_blocks = db.get_indexed_blocks().await.unwrap();

loop {
sync_chain(&rpc, &db, &mut config).await;
sync_chain(&rpc, &db, &mut config, &mut indexed_blocks).await;

sleep(Duration::from_millis(500))
}
Expand All @@ -64,9 +66,12 @@ async fn main() {
}
}

async fn sync_chain(rpc: &Rpc, db: &Database, config: &EVMIndexerConfig) {
let mut indexed_blocks = db.get_indexed_blocks().await.unwrap();

async fn sync_chain(
rpc: &Rpc,
db: &Database,
config: &EVMIndexerConfig,
indexed_blocks: &mut HashSet<i64>,
) {
let db_state = DatabaseChainIndexedState {
chain: config.chain.name.to_string(),
indexed_blocks_amount: indexed_blocks.len() as i64,
Expand Down
18 changes: 16 additions & 2 deletions src/db/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,24 @@ impl Database {
pub async fn get_indexed_blocks(&self) -> Result<HashSet<i64>> {
let mut connection = self.redis.get_connection().unwrap();

let blocks: HashSet<i64> = connection
.smembers::<String, HashSet<i64>>(self.chain.name.to_owned())
let keys: Vec<String> = connection
.keys(format!("{}*", self.chain.name.to_string()))
.unwrap();

let mut blocks: HashSet<i64> = HashSet::new();

for key in keys {
let chunk_blocks: HashSet<i64> = match connection.get::<String, String>(key) {
Ok(blocks) => match serde_json::from_str(&blocks) {
Ok(deserialized) => deserialized,
Err(_) => continue,
},
Err(_) => continue,
};

blocks.extend(&chunk_blocks);
}

Ok(blocks)
}

Expand Down

0 comments on commit 1c7fa44

Please sign in to comment.