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;
|
2025-04-08 04:39:01 +00:00
|
|
|
use ruma::OwnedUserId;
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
use crate::Command;
|
|
|
|
|
|
|
|
|
|
#[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
|
2025-04-08 04:39:01 +00:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
}
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-04-20 17:02:24 -04:00
|
|
|
/// All the getters and iterators in key_value/presence.rs
|
2025-01-04 16:57:07 +00:00
|
|
|
pub(super) async fn process(subcommand: PresenceCommand, context: &Command<'_>) -> Result {
|
2024-07-27 00:11:41 +00:00
|
|
|
let services = context.services;
|
|
|
|
|
|
2024-04-20 14:44:31 -04:00
|
|
|
match subcommand {
|
2024-12-15 00:05:47 -05:00
|
|
|
| PresenceCommand::GetPresence { user_id } => {
|
2024-04-20 14:44:31 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2025-01-10 23:51:08 -05:00
|
|
|
let results = services.presence.get_presence(&user_id).await;
|
2024-04-20 14:44:31 -04:00
|
|
|
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```")
|
2024-04-20 14:44:31 -04:00
|
|
|
},
|
2024-12-15 00:05:47 -05:00
|
|
|
| PresenceCommand::PresenceSince { since } => {
|
2024-04-20 14:44:31 -04:00
|
|
|
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;
|
2024-07-01 20:35:39 +00:00
|
|
|
let query_time = timer.elapsed();
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
2024-04-20 14:44:31 -04:00
|
|
|
},
|
|
|
|
|
}
|
2025-01-04 16:57:07 +00:00
|
|
|
.await
|
2024-04-20 14:44:31 -04:00
|
|
|
}
|