mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2024-12-22 14:35:02 +01:00
Improved collection loading
This commit is contained in:
parent
68a4230200
commit
69e624f82b
1 changed files with 8 additions and 15 deletions
|
@ -66,26 +66,19 @@ impl Collection {
|
||||||
.first::<Self>(&**conn).ok()
|
.first::<Self>(&**conn).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_user_uuid(uuid: &str, conn: &DbConn) -> Vec<Self> {
|
pub fn find_by_user_uuid(user_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
||||||
match users_collections::table
|
users_collections::table.inner_join(collections::table)
|
||||||
.filter(users_collections::user_uuid.eq(uuid))
|
.filter(users_collections::user_uuid.eq(user_uuid))
|
||||||
.select(users_collections::columns::collection_uuid)
|
.select(collections::all_columns)
|
||||||
.load(&**conn) {
|
.load::<Self>(&**conn).expect("Error loading user collections")
|
||||||
Ok(uuids) => uuids.iter().map(|uuid: &String| {
|
|
||||||
Collection::find_by_uuid(uuid, &conn).unwrap()
|
|
||||||
}).collect(),
|
|
||||||
Err(list) => vec![]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_uuid_and_user(uuid: &str, user_uuid: &str, conn: &DbConn) -> Option<Self> {
|
pub fn find_by_uuid_and_user(uuid: &str, user_uuid: &str, conn: &DbConn) -> Option<Self> {
|
||||||
match users_collections::table
|
users_collections::table.inner_join(collections::table)
|
||||||
.filter(users_collections::collection_uuid.eq(uuid))
|
.filter(users_collections::collection_uuid.eq(uuid))
|
||||||
.filter(users_collections::user_uuid.eq(user_uuid))
|
.filter(users_collections::user_uuid.eq(user_uuid))
|
||||||
.first::<CollectionUsers>(&**conn).ok() {
|
.select(collections::all_columns)
|
||||||
None => None,
|
.first::<Self>(&**conn).ok()
|
||||||
Some(collection_user) => Collection::find_by_uuid(&collection_user.collection_uuid, &conn)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue