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.

54 lines
1.5 KiB
Rust
Raw Normal View History

2024-07-27 00:11:41 +00:00
use clap::Subcommand;
2024-08-08 17:18:30 +00:00
use futures::StreamExt;
use ruma::OwnedUserId;
2025-04-22 01:41:02 +00:00
use tuwunel_core::Result;
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
pub(crate) enum PresenceCommand {
/// - 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,
2025-07-26 04:59:00 +00:00
/// Upper-bound of since
to: Option<u64>,
2024-07-27 00:11:41 +00:00
},
}
/// 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```")
},
2025-07-26 04:59:00 +00:00
| PresenceCommand::PresenceSince { since, to } => {
let timer = tokio::time::Instant::now();
2024-10-22 03:28:45 +00:00
let results: Vec<(_, _, _)> = services
.presence
2025-07-26 04:59:00 +00:00
.presence_since(since, to)
2024-10-22 03:28:45 +00:00
.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
}