2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
2024-12-14 21:58:01 -05:00
|
|
|
use conduwuit::Result;
|
2024-11-19 03:08:09 +00:00
|
|
|
use futures::StreamExt;
|
2025-04-06 23:41:58 +00:00
|
|
|
use ruma::{OwnedRoomId, OwnedUserId};
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
use crate::{admin_command, admin_command_dispatch};
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
#[admin_command_dispatch]
|
2024-07-27 00:11:41 +00:00
|
|
|
#[derive(Debug, Subcommand)]
|
2024-04-20 17:02:24 -04:00
|
|
|
/// 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
|
2025-04-08 04:39:01 +00:00
|
|
|
user_id: OwnedUserId,
|
2024-07-27 00:11:41 +00:00
|
|
|
/// UNIX timestamp since (u64)
|
|
|
|
since: u64,
|
|
|
|
/// Optional room ID of the account data
|
2025-04-08 04:39:01 +00:00
|
|
|
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
|
2025-04-08 04:39:01 +00:00
|
|
|
user_id: OwnedUserId,
|
2024-07-27 00:11:41 +00:00
|
|
|
/// Account data event type
|
2024-10-02 07:57:18 +00:00
|
|
|
kind: String,
|
2024-07-27 00:11:41 +00:00
|
|
|
/// Optional room ID of the account data
|
2025-04-08 04:39:01 +00:00
|
|
|
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,
|
2025-04-08 04:39:01 +00:00
|
|
|
user_id: OwnedUserId,
|
2025-01-04 16:57:07 +00:00
|
|
|
since: u64,
|
2025-04-08 04:39:01 +00:00
|
|
|
room_id: Option<OwnedRoomId>,
|
2025-04-06 23:41:58 +00:00
|
|
|
) -> Result {
|
2025-01-04 16:57:07 +00:00
|
|
|
let timer = tokio::time::Instant::now();
|
|
|
|
let results: Vec<_> = self
|
|
|
|
.services
|
|
|
|
.account_data
|
2025-01-31 13:51:39 +00:00
|
|
|
.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
|
|
|
|
2025-04-06 23:41:58 +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
|
|
|
}
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
#[admin_command]
|
|
|
|
async fn account_data_get(
|
|
|
|
&self,
|
2025-04-08 04:39:01 +00:00
|
|
|
user_id: OwnedUserId,
|
2025-01-04 16:57:07 +00:00
|
|
|
kind: String,
|
2025-04-08 04:39:01 +00:00
|
|
|
room_id: Option<OwnedRoomId>,
|
2025-04-06 23:41:58 +00:00
|
|
|
) -> 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();
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2025-04-06 23:41:58 +00:00
|
|
|
self.write_str(&format!("Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"))
|
|
|
|
.await
|
2024-04-20 14:44:31 -04:00
|
|
|
}
|