Skip to content

Commit

Permalink
prevents duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 24, 2024
1 parent 355891b commit 0f3f90e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion warehouse/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ pub async fn commit_batch_query(pool: &SqlitePool, batch_accounts: &[WarehouseAc
b.push_bind(acc.address.to_hex_literal()).push_bind(true);
});

// makes sure the txs don't fail on repeated attempts to add users
query_builder.push("ON CONFLICT (account_address) DO NOTHING");

let query = query_builder.build();
query.execute(pool).await?;
let _res = query.execute(pool).await?;

Ok(())
}
5 changes: 5 additions & 0 deletions warehouse/tests/test_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ async fn batch_duplicates_fail_gracefully(pool: SqlitePool) -> anyhow::Result<()
vec_acct.push(acc);
}

// should not fail if duplicates exists on same batch
libra_warehouse::load::commit_batch_query(&pool, &vec_acct).await?;

// also should not fail if duplicates are on separate batches
libra_warehouse::load::commit_batch_query(&pool, &vec_acct).await?;

Ok(())
}

Expand Down

0 comments on commit 0f3f90e

Please sign in to comment.