Skip to content

Commit

Permalink
fix: handle key '/user/' not exist in dynamodb when tables are create…
Browse files Browse the repository at this point in the history
…d first time (openobserve#1486)
  • Loading branch information
taimingl committed Sep 12, 2023
1 parent 9d1f82d commit 3441bff
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/service/db/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,19 @@ pub async fn cache() -> Result<(), anyhow::Error> {
pub async fn root_user_exists() -> bool {
let db = &infra_db::DEFAULT;
let key = "/user/";
let mut ret = db.list_values(key).await.unwrap();
ret.retain(|item| {
let user: DBUser = json::from_slice(item).unwrap();
user.organizations
.first()
.as_ref()
.unwrap()
.role
.eq(&crate::common::meta::user::UserRole::Root)
});
!ret.is_empty()
if let Ok(mut ret) = db.list_values(key).await {
ret.retain(|item| {
let user: DBUser = json::from_slice(item).unwrap();
user.organizations
.first()
.as_ref()
.unwrap()
.role
.eq(&crate::common::meta::user::UserRole::Root)
});
return !ret.is_empty();
}
false
}

pub async fn reset() -> Result<(), anyhow::Error> {
Expand Down

0 comments on commit 3441bff

Please sign in to comment.