Skip to content

Commit

Permalink
Distinguish between initialization client and insertion client instan…
Browse files Browse the repository at this point in the history
…ces.
  • Loading branch information
arik-so committed Mar 20, 2024
1 parent c6667ef commit 2fab4ba
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
}

pub(crate) async fn persist_gossip(&mut self) {
let mut client = crate::connect_to_db().await;
{ // initialize the database
// this client instance is only used once
let mut client = crate::connect_to_db().await;

{
// initialize the database
let initialization = client
.execute(config::db_config_table_creation_query(), &[])
.await;
Expand Down Expand Up @@ -122,14 +122,17 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
insert_limiter.acquire().await.unwrap().forget();

let limiter_ref = Arc::clone(&insert_limiter);
let connections_cache_ref = Arc::clone(&connections_cache);
let client = {
let connections_cache_ref = Arc::clone(&connections_cache);

let mut connections_set = connections_cache_ref.lock().await;
let client = if connections_set.is_empty() {
drop(connections_set);
crate::connect_to_db().await
} else {
connections_set.pop().unwrap()
let mut connections_set = connections_cache_ref.lock().await;
let client = if connections_set.is_empty() {
drop(connections_set);
crate::connect_to_db().await
} else {
connections_set.pop().unwrap()
};
client
};

let connections_cache_ref = Arc::clone(&connections_cache);
Expand Down

0 comments on commit 2fab4ba

Please sign in to comment.