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

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

71 lines
1.7 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;
use futures::StreamExt;
use ruma::{OwnedRoomId, OwnedUserId};
2025-01-04 16:57:07 +00:00
use crate::{admin_command, admin_command_dispatch};
2025-01-04 16:57:07 +00:00
#[admin_command_dispatch]
2024-07-27 00:11:41 +00:00
#[derive(Debug, Subcommand)]
/// All the getters and iterators from src/database/key_value/account_data.rs
2024-07-27 00:11:41 +00:00
pub(crate) enum AccountDataCommand {
/// - Returns all changes to the account data that happened after `since`.
ChangesSince {
/// Full user ID
user_id: OwnedUserId,
2024-07-27 00:11:41 +00:00
/// UNIX timestamp since (u64)
since: u64,
/// Optional room ID of the account data
room_id: Option<OwnedRoomId>,
2024-07-27 00:11:41 +00:00
},
/// - Searches the account data for a specific kind.
2025-01-04 16:57:07 +00:00
AccountDataGet {
2024-07-27 00:11:41 +00:00
/// Full user ID
user_id: OwnedUserId,
2024-07-27 00:11:41 +00:00
/// Account data event type
kind: String,
2024-07-27 00:11:41 +00:00
/// Optional room ID of the account data
room_id: Option<OwnedRoomId>,
2024-07-27 00:11:41 +00:00
},
}
2025-01-04 16:57:07 +00:00
#[admin_command]
async fn changes_since(
&self,
user_id: OwnedUserId,
2025-01-04 16:57:07 +00:00
since: u64,
room_id: Option<OwnedRoomId>,
) -> Result {
2025-01-04 16:57:07 +00:00
let timer = tokio::time::Instant::now();
let results: Vec<_> = self
.services
.account_data
.changes_since(room_id.as_deref(), &user_id, since, None)
2025-01-04 16:57:07 +00:00
.collect()
.await;
let query_time = timer.elapsed();
2024-07-27 00:11:41 +00:00
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
.await
2025-01-04 16:57:07 +00:00
}
2025-01-04 16:57:07 +00:00
#[admin_command]
async fn account_data_get(
&self,
user_id: OwnedUserId,
2025-01-04 16:57:07 +00:00
kind: String,
room_id: Option<OwnedRoomId>,
) -> Result {
2025-01-04 16:57:07 +00:00
let timer = tokio::time::Instant::now();
let results = self
.services
.account_data
.get_raw(room_id.as_deref(), &user_id, &kind)
.await;
let query_time = timer.elapsed();
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
.await
}