mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-27 01:36:36 +02:00
Some checks failed
Release Docker Image / define-variables (push) Failing after 1s
Release Docker Image / build-image (linux/amd64, linux-amd64) (push) Has been skipped
Release Docker Image / build-image (linux/arm64, linux-arm64) (push) Has been skipped
Release Docker Image / merge (push) Has been skipped
Rust Checks / Format (push) Failing after 1s
Rust Checks / Clippy (push) Failing after 9s
Rust Checks / Cargo Test (push) Failing after 8s
The first part of getting admin command docs on the website. Next is is including it in the same way we do the example config or readme. There's also the beginnings of manpage generation here, although it's kinda sus and I'm not sure how it's supposed to work. I'll leave that to anyone who wants to package it. We introduce the beginings of the xtask pattern here - we do a lot of file generation, I thought it would be best to avoid doing that on every compilation. It also helps avoid lots of runtime deps. We'll need to document generating this stuff & probably add pre-commit hooks for it, though.
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use clap::Subcommand;
|
|
use conduwuit::Result;
|
|
use futures::StreamExt;
|
|
use ruma::OwnedUserId;
|
|
|
|
use crate::Context;
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
/// All the getters and iterators from src/database/key_value/presence.rs
|
|
pub enum PresenceCommand {
|
|
/// - Returns the latest presence event for the given user.
|
|
GetPresence {
|
|
/// Full user ID
|
|
user_id: OwnedUserId,
|
|
},
|
|
|
|
/// - 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 {
|
|
let services = context.services;
|
|
|
|
match subcommand {
|
|
| PresenceCommand::GetPresence { user_id } => {
|
|
let timer = tokio::time::Instant::now();
|
|
let results = services.presence.get_presence(&user_id).await;
|
|
let query_time = timer.elapsed();
|
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
|
},
|
|
| PresenceCommand::PresenceSince { since } => {
|
|
let timer = tokio::time::Instant::now();
|
|
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();
|
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
|
},
|
|
}
|
|
.await
|
|
}
|