Revert "Add sql transactions"

This caused the error "locked database".
This reverts commit 9823511b62.
This commit is contained in:
Tobias Reisinger 2024-05-02 19:33:25 +02:00
parent 9823511b62
commit 02c613e0fd
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
9 changed files with 138 additions and 171 deletions

View file

@ -63,10 +63,9 @@ impl AppState {
}
fn get_relays(&self) -> Result<Vec<Relay>, EmgauwaError> {
let mut tx = block_on(self.pool.begin())?;
let db_controllers = block_on(DbController::get_all(&mut tx))?;
let mut controllers: Vec<Controller> = convert_db_list(&mut tx, db_controllers)?;
block_on(tx.commit())?;
let mut pool_conn = block_on(self.pool.acquire())?;
let db_controllers = block_on(DbController::get_all(&mut pool_conn))?;
let mut controllers: Vec<Controller> = convert_db_list(&mut pool_conn, db_controllers)?;
self.connected_controllers
.iter()
@ -114,11 +113,11 @@ impl Handler<DisconnectController> for AppState {
type Result = Result<(), EmgauwaError>;
fn handle(&mut self, msg: DisconnectController, _ctx: &mut Self::Context) -> Self::Result {
let mut tx = block_on(self.pool.begin())?;
let mut pool_conn = block_on(self.pool.acquire())?;
if let Some((controller, address)) = self.connected_controllers.remove(&msg.controller_uid)
{
if let Err(err) = block_on(controller.c.update_active(&mut tx, false)) {
if let Err(err) = block_on(controller.c.update_active(&mut pool_conn, false)) {
log::error!(
"Failed to mark controller {} as inactive: {:?}",
controller.c.uid,
@ -129,7 +128,6 @@ impl Handler<DisconnectController> for AppState {
//block_on(address.send(ControllerWsAction::Disconnect))??;
address.do_send(ControllerWsAction::Disconnect);
}
block_on(tx.commit())?;
self.notify_relay_clients();
Ok(())
}