mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-13 12:16:54 +00:00
refactor: Remove list_local_users function
This commit is contained in:
6 files changed
+10
-20
No files matched your search
@@ -35,7 +35,7 @@ impl crate::Context<'_> {
|
||||
let users: Vec<_> = self
|
||||
.services
|
||||
.users
|
||||
.list_local_users()
|
||||
.stream_local_users()
|
||||
.map(|id| id.as_str().to_owned())
|
||||
.collect()
|
||||
.await;
|
||||
@@ -588,7 +588,7 @@ impl crate::Context<'_> {
|
||||
for user_id in &self
|
||||
.services
|
||||
.users
|
||||
.list_local_users()
|
||||
.stream_local_users()
|
||||
.collect::<Vec<_>>()
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ pub(crate) async fn continuwuity_server_version() -> Result<impl IntoResponse> {
|
||||
pub(crate) async fn continuwuity_local_user_count(
|
||||
State(services): State<crate::State>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
let user_count = services.users.list_local_users().count().await;
|
||||
let user_count = services.users.stream_local_users().count().await;
|
||||
|
||||
Ok(Json(serde_json::json!({
|
||||
"count": user_count
|
||||
|
||||
@@ -73,7 +73,7 @@ impl crate::Service for Service {
|
||||
&& self
|
||||
.services
|
||||
.users
|
||||
.list_local_users()
|
||||
.stream_local_users()
|
||||
.ready_filter(|user| *user != self.services.globals.server_user)
|
||||
.next()
|
||||
.await
|
||||
|
||||
@@ -315,7 +315,8 @@ async fn migrate(services: &Services) -> Result<()> {
|
||||
async fn db_lt_12(services: &Services) -> Result<()> {
|
||||
for username in &services
|
||||
.users
|
||||
.list_local_users()
|
||||
.stream_local_users()
|
||||
.ready_filter(|user| services.globals.user_is_local(user))
|
||||
.collect::<Vec<OwnedUserId>>()
|
||||
.await
|
||||
{
|
||||
@@ -394,7 +395,8 @@ async fn db_lt_12(services: &Services) -> Result<()> {
|
||||
async fn db_lt_13(services: &Services) -> Result<()> {
|
||||
for username in &services
|
||||
.users
|
||||
.list_local_users()
|
||||
.stream_local_users()
|
||||
.ready_filter(|user| services.globals.user_is_local(user))
|
||||
.collect::<Vec<OwnedUserId>>()
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -182,7 +182,7 @@ impl Service {
|
||||
for user_id in &self
|
||||
.services
|
||||
.users
|
||||
.list_local_users()
|
||||
.stream_local_users()
|
||||
.collect::<Vec<OwnedUserId>>()
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::time::{Duration, SystemTime};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Result, debug_error, debug_warn, err, error, info, trace,
|
||||
utils::{self, ReadyExt, stream::TryIgnore},
|
||||
utils::{self, stream::TryIgnore},
|
||||
warn,
|
||||
};
|
||||
use database::{Deserialized, Json};
|
||||
@@ -557,18 +557,6 @@ impl super::Service {
|
||||
self.db.userid_password.keys().ignore_err()
|
||||
}
|
||||
|
||||
/// Returns a list of active local users.
|
||||
///
|
||||
/// A user account is considered `local` if the associated password is not
|
||||
/// empty.
|
||||
pub fn list_local_users(&self) -> impl Stream<Item = OwnedUserId> + Send + '_ {
|
||||
self.db
|
||||
.userid_password
|
||||
.stream()
|
||||
.ignore_err()
|
||||
.ready_filter_map(|(u, p): (OwnedUserId, &[u8])| (!p.is_empty()).then_some(u))
|
||||
}
|
||||
|
||||
/// Set a user's password.
|
||||
pub async fn set_password(&self, user_id: &UserId, password: HashedPassword) -> Result {
|
||||
self.status(user_id).await.ensure_active()?;
|
||||
|
||||
Reference in new issue
Block a user