Skip to content

Commit

Permalink
feat(api): Enhance MongoDB query for accurate total count of bridged …
Browse files Browse the repository at this point in the history
…tokens
  • Loading branch information
remiroyc committed Apr 8, 2024
1 parent 7da8c52 commit c71eec1
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions apps/indexer/src/storage/mongo/event_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,15 @@ impl EventStore for MongoStore {
&self,
eth_contract_address: &str,
) -> Result<u64> {
let pipeline = vec![
doc! {
"$match": {
"collection_src": eth_contract_address,
}
},
doc! {
"$project": {
"number_of_tokens": { "$size": "$token_ids" }
}
},
doc! {
"$group": {
"_id": null,
"total_token_ids": { "$sum": "$number_of_tokens" }
}
},
];
let filter = doc! {
"collection_src": eth_contract_address,
};

let mut cursor = self
let total_count = self
.starknet_bridge_requests
.aggregate(pipeline, None)
.count_documents(filter, None)
.await?;

let mut total_count: u64 = 0;
if let Some(doc) = cursor.try_next().await? {
if let Ok(count) = doc.get_i64("total_token_ids") {
total_count = count as u64;
}
}

Ok(total_count)
}

Expand Down

0 comments on commit c71eec1

Please sign in to comment.