From e407409f044ecb81c382d90caf0b2388f84720f2 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 14 May 2022 13:02:42 -0600 Subject: [PATCH] make inmemorytransaction actually work --- src/entity/gateway/inmemory.rs | 45 +++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 9b8d1ab..3fd7cc6 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -21,18 +21,39 @@ impl<'a> EntityGatewayTransaction for InMemoryGatewayTransaction<'a> { &mut self.working_gateway } - async fn commit(self: Box) -> Result<(), GatewayError> { - self.original_gateway.users = self.working_gateway.users.clone(); - self.original_gateway.user_settings = self.working_gateway.user_settings.clone(); - self.original_gateway.characters = self.working_gateway.characters.clone(); - self.original_gateway.character_meseta = self.working_gateway.character_meseta.clone(); - self.original_gateway.bank_meseta = self.working_gateway.bank_meseta.clone(); - self.original_gateway.items = self.working_gateway.items.clone(); - self.original_gateway.inventories = self.working_gateway.inventories.clone(); - self.original_gateway.banks = self.working_gateway.banks.clone(); - self.original_gateway.equips = self.working_gateway.equips.clone(); - self.original_gateway.mag_modifiers = self.working_gateway.mag_modifiers.clone(); - self.original_gateway.weapon_modifiers = self.working_gateway.weapon_modifiers.clone(); + async fn commit(mut self: Box) -> Result<(), GatewayError> { + self.original_gateway.users.lock().unwrap().clear(); + self.original_gateway.users.lock().unwrap().extend(self.working_gateway.users.lock().unwrap().clone()); + + self.original_gateway.user_settings.lock().unwrap().clear(); + self.original_gateway.user_settings.lock().unwrap().extend(self.working_gateway.user_settings.lock().unwrap().clone()); + + self.original_gateway.characters.lock().unwrap().clear(); + self.original_gateway.characters.lock().unwrap().extend(self.working_gateway.characters.lock().unwrap().clone()); + + self.original_gateway.character_meseta.lock().unwrap().clear(); + self.original_gateway.character_meseta.lock().unwrap().extend(self.working_gateway.character_meseta.lock().unwrap().clone()); + + self.original_gateway.bank_meseta.lock().unwrap().clear(); + self.original_gateway.bank_meseta.lock().unwrap().extend(self.working_gateway.bank_meseta.lock().unwrap().clone()); + + self.original_gateway.items.lock().unwrap().clear(); + self.original_gateway.items.lock().unwrap().extend(self.working_gateway.items.lock().unwrap().clone()); + + self.original_gateway.inventories.lock().unwrap().clear(); + self.original_gateway.inventories.lock().unwrap().extend(self.working_gateway.inventories.lock().unwrap().clone()); + + self.original_gateway.banks.lock().unwrap().clear(); + self.original_gateway.banks.lock().unwrap().extend(self.working_gateway.banks.lock().unwrap().clone()); + + self.original_gateway.equips.lock().unwrap().clear(); + self.original_gateway.equips.lock().unwrap().extend(self.working_gateway.equips.lock().unwrap().clone()); + + self.original_gateway.mag_modifiers.lock().unwrap().clear(); + self.original_gateway.mag_modifiers.lock().unwrap().extend(self.working_gateway.mag_modifiers.lock().unwrap().clone()); + + self.original_gateway.weapon_modifiers.lock().unwrap().clear(); + self.original_gateway.weapon_modifiers.lock().unwrap().extend(self.working_gateway.weapon_modifiers.lock().unwrap().clone()); Ok(()) }