Skip to content

Commit

Permalink
[server] Fix logic race conditon in db_list #1157 (#1165)
Browse files Browse the repository at this point in the history
* Update test_queries.json

* Update multi_map.rs

* Update db_value.rs

* add select elements

* Update db_pool.rs

* update docs

* Update query.test.ts

* Update test_queries.json

* update test org

* Update db_pool.rs
  • Loading branch information
michaelvlach authored Jul 29, 2024
1 parent 105a6e3 commit 9f164c1
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions agdb_server/src/db_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl DbPool {
.await
.exec(
&QueryBuilder::select()
.elements::<Database>()
.ids(
QueryBuilder::search()
.from("dbs")
Expand Down Expand Up @@ -652,11 +653,13 @@ impl DbPool {
}

pub(crate) async fn find_dbs(&self) -> ServerResult<Vec<ServerDatabase>> {
let pool = self.get_pool().await;
let dbs: Vec<Database> = self
.db()
.await
.exec(
&QueryBuilder::select()
.elements::<Database>()
.ids(
QueryBuilder::search()
.from("dbs")
Expand All @@ -674,9 +677,7 @@ impl DbPool {
databases.push(ServerDatabase {
db_type: db.db_type,
role: DbUserRole::Admin,
size: self
.get_pool()
.await
size: pool
.get(&db.name)
.ok_or(db_not_found(&db.name))?
.get()
Expand Down Expand Up @@ -767,7 +768,12 @@ impl DbPool {
Ok(self
.db()
.await
.exec(&QueryBuilder::select().ids(user_id).query())?
.exec(
&QueryBuilder::select()
.elements::<ServerUser>()
.ids(user_id)
.query(),
)?
.try_into()?)
}

Expand Down Expand Up @@ -797,7 +803,12 @@ impl DbPool {
Ok(self
.db()
.await
.exec(&QueryBuilder::select().ids(user).query())?
.exec(
&QueryBuilder::select()
.elements::<ServerUser>()
.ids(user)
.query(),
)?
.try_into()?)
}

Expand Down Expand Up @@ -1178,7 +1189,12 @@ impl DbPool {
.first()
.ok_or(db_not_found(db))?
.id;
Ok(t.exec(&QueryBuilder::select().ids(db_id).query())?)
Ok(t.exec(
&QueryBuilder::select()
.elements::<Database>()
.ids(db_id)
.query(),
)?)
})?
.try_into()?)
}
Expand All @@ -1189,6 +1205,7 @@ impl DbPool {
.await
.exec(
&QueryBuilder::select()
.elements::<Database>()
.ids(
QueryBuilder::search()
.depth_first()
Expand Down

0 comments on commit 9f164c1

Please sign in to comment.