Added more paralization to allow better multi-user perfomace

This commit is contained in:
2023-05-04 18:27:19 +03:00
parent ecf74fb50f
commit 17e4f1892c
6 changed files with 30 additions and 23 deletions

View File

@ -1,6 +1,7 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2
use chacha20poly1305::{aead::Aead, AeadCore, ChaCha20Poly1305, KeyInit};
use futures::{Stream, StreamExt};
use pbkdf2::pbkdf2_hmac_array;
use rand::{rngs::OsRng, RngCore};
use sea_orm::{prelude::*, ActiveValue::Set, QuerySelect};
@ -88,14 +89,18 @@ impl Model {
impl Entity {
/// Gets a list of account names of a user
pub async fn get_names(user_id: u64, db: &DatabaseConnection) -> crate::Result<Vec<String>> {
Self::find()
pub async fn get_names(
user_id: u64,
db: &DatabaseConnection,
) -> crate::Result<impl Stream<Item = crate::Result<String>> + '_> {
let result = Self::find()
.select_only()
.column(Column::Name)
.filter(Column::UserId.eq(user_id))
.into_tuple()
.all(db)
.await
.map_err(|err| err.into())
.stream(db)
.await?
.map(|item| item.map_err(Into::into));
Ok(result)
}
}