Files
continuwuity/src/admin/query/presence.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.4 KiB
Rust
Raw Normal View History

2024-07-27 00:11:41 +00:00
use clap::Subcommand;
2024-12-14 21:58:01 -05:00
use conduwuit::Result;
2024-08-08 17:18:30 +00:00
use futures::StreamExt;
use ruma::OwnedUserId;
use crate::Context;
2024-07-27 00:11:41 +00:00
#[derive(Debug, Subcommand)]
/// All the getters and iterators from src/database/key_value/presence.rs
2025-05-24 00:28:09 +01:00
pub enum PresenceCommand {
2024-07-27 00:11:41 +00:00
/// - Returns the latest presence event for the given user.
GetPresence {
/// Full user ID
user_id: OwnedUserId,
2024-07-27 00:11:41 +00:00
},
/// - Iterator of the most recent presence updates that happened after the
/// event with id `since`.
PresenceSince {
/// UNIX timestamp since (u64)
since: u64,
},
}
/// All the getters and iterators in key_value/presence.rs
pub(super) async fn process(subcommand: PresenceCommand, context: &Context<'_>) -> Result {
2024-07-27 00:11:41 +00:00
let services = context.services;
match subcommand {
| PresenceCommand::GetPresence { user_id } => {
let timer = tokio::time::Instant::now();
2025-01-10 23:51:08 -05:00
let results = services.presence.get_presence(&user_id).await;
let query_time = timer.elapsed();
2025-01-04 16:57:07 +00:00
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
},
| PresenceCommand::PresenceSince { since } => {
let timer = tokio::time::Instant::now();
2024-10-22 03:28:45 +00:00
let results: Vec<(_, _, _)> = services
.presence
.presence_since(since)
.map(|(user_id, count, bytes)| (user_id.to_owned(), count, bytes.to_vec()))
.collect()
.await;
let query_time = timer.elapsed();
2025-01-04 16:57:07 +00:00
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
},
}
2025-01-04 16:57:07 +00:00
.await
}