refactor (backend-rs): provide DbConn as an argument of user::count::local_total
This commit is contained in:
parent
ca6b840302
commit
85a1db7981
2 changed files with 7 additions and 5 deletions
|
@ -34,7 +34,7 @@ async fn statistics() -> Result<(u64, u64, u64, u64), DbErr> {
|
|||
const MONTH: chrono::TimeDelta = chrono::Duration::days(30);
|
||||
const HALF_YEAR: chrono::TimeDelta = chrono::Duration::days(183);
|
||||
|
||||
let local_users = misc::user::count::local_total();
|
||||
let local_users = misc::user::count::local_total(db);
|
||||
let local_active_halfyear = user::Entity::find()
|
||||
.filter(user::Column::Host.is_null())
|
||||
.filter(user::Column::LastActiveDate.gt(now - HALF_YEAR))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{database::db_conn, model::entity::user};
|
||||
use crate::model::entity::user;
|
||||
use sea_orm::prelude::*;
|
||||
|
||||
// TODO: When `std::mem::variant_count` is stabilized, use
|
||||
|
@ -7,15 +7,17 @@ use sea_orm::prelude::*;
|
|||
// @instance.actor and @relay.actor are not real users
|
||||
const NUMBER_OF_SYSTEM_ACTORS: u64 = 2;
|
||||
|
||||
pub async fn local_total() -> Result<u64, DbErr> {
|
||||
pub async fn local_total(db: &DbConn) -> Result<u64, DbErr> {
|
||||
user::Entity::find()
|
||||
.filter(user::Column::Host.is_null())
|
||||
.count(db_conn().await?)
|
||||
.count(db)
|
||||
.await
|
||||
.map(|count| count - NUMBER_OF_SYSTEM_ACTORS)
|
||||
}
|
||||
|
||||
#[macros::ts_export(js_name = "countLocalUsers")]
|
||||
pub async fn local_total_js() -> Result<u32, DbErr> {
|
||||
local_total().await.map(|count| count as u32)
|
||||
local_total(crate::database::db_conn().await?)
|
||||
.await
|
||||
.map(|count| count as u32)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue