From 2a6bb24c9b6899b516db6fcb2dbab75188ccc81d Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:08:00 -0500 Subject: [PATCH] better error handling --- src/analytics/enrich_account_funding.rs | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/analytics/enrich_account_funding.rs b/src/analytics/enrich_account_funding.rs index d75522c..0775435 100644 --- a/src/analytics/enrich_account_funding.rs +++ b/src/analytics/enrich_account_funding.rs @@ -189,20 +189,28 @@ impl BalanceTracker { Ok(format!("[{}]", list_literal)) } + pub async fn submit_one_id(&self, id: u32, pool: &Graph) -> Result { + let data = self.to_cypher_map(id)?; + let query_literal = generate_cypher_query(data); + let query = Query::new(query_literal); + let mut result = pool.execute(query).await?; + + let row = result.next().await?.context("no row returned")?; + + let merged: u64 = row + .get("merged_relations") + .context("no unique_accounts field")?; + + trace!("merged ledger in tx: {merged}"); + Ok(merged) + } /// submit to db pub async fn submit_ledger(&self, pool: &Graph) -> Result { let mut merged_relations = 0u64; for id in self.0.keys() { - let data = self.to_cypher_map(*id)?; - let query_literal = generate_cypher_query(data); - let query = Query::new(query_literal); - let mut result = pool.execute(query).await?; - - while let Some(r) = result.next().await? { - if let Ok(i) = r.get::("merged_relations") { - trace!("merged ledger in tx: {i}"); - merged_relations += i; - }; + match self.submit_one_id(*id, pool).await { + Ok(m) => merged_relations += m, + Err(e) => error!("could not submit user ledger: {}", e), } } Ok(merged_relations)