From 6b70354fbb5d39ba1b6d9e1614d5780076c2f078 Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 15 May 2020 16:40:06 -0400 Subject: [PATCH] Wrap updates in transaction --- server/src/persistence/stats.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/persistence/stats.rs b/server/src/persistence/stats.rs index 1d722971a9..52aecea414 100644 --- a/server/src/persistence/stats.rs +++ b/server/src/persistence/stats.rs @@ -21,9 +21,15 @@ fn update(character_id: i32, stats: &StatsUpdate, connection: &SqliteConnection) fn batch_update(updates: impl Iterator, db_dir: &str) { let connection = establish_connection(db_dir); + if let Err(err) = connection.transaction::<_, diesel::result::Error, _>(|| { + updates.for_each(|(character_id, stats_update)| { + update(character_id, &stats_update, &connection) + }); - updates - .for_each(|(character_id, stats_update)| update(character_id, &stats_update, &connection)); + Ok(()) + }) { + log::error!("Error during stats batch update transaction: {:?}", err); + } } pub struct Updater {