Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Fix logic race conditon in db_list #1157 #1165

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