mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
feat(admin): Add resolver cache flush command
This command allows an admin to flush a specific server from the resolver caches or flush the whole cache.
This commit is contained in:
@@ -112,6 +112,19 @@ Query the destinations cache
|
|||||||
|
|
||||||
Query the overrides cache
|
Query the overrides cache
|
||||||
|
|
||||||
|
### `!admin query resolver flush-cache`
|
||||||
|
|
||||||
|
Flush a given server from the resolver caches or flush them completely
|
||||||
|
|
||||||
|
* Examples:
|
||||||
|
* Flush a specific server:
|
||||||
|
|
||||||
|
`!admin query resolver flush-cache matrix.example.com`
|
||||||
|
|
||||||
|
* Flush all resolver caches completely:
|
||||||
|
|
||||||
|
`!admin query resolver flush-cache --all`
|
||||||
|
|
||||||
## `!admin query pusher`
|
## `!admin query pusher`
|
||||||
|
|
||||||
pusher service
|
pusher service
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use conduwuit::{Result, utils::time};
|
use conduwuit::{Err, Result, utils::time};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::OwnedServerName;
|
use ruma::OwnedServerName;
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ use crate::{admin_command, admin_command_dispatch};
|
|||||||
|
|
||||||
#[admin_command_dispatch]
|
#[admin_command_dispatch]
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
/// Resolver service and caches
|
/// Resolver service and caches
|
||||||
pub enum ResolverCommand {
|
pub enum ResolverCommand {
|
||||||
/// Query the destinations cache
|
/// Query the destinations cache
|
||||||
@@ -18,6 +19,14 @@ pub enum ResolverCommand {
|
|||||||
OverridesCache {
|
OverridesCache {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Flush a specific server from the resolver caches or everything
|
||||||
|
FlushCache {
|
||||||
|
name: Option<OwnedServerName>,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
all: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[admin_command]
|
#[admin_command]
|
||||||
@@ -69,3 +78,18 @@ async fn overrides_cache(&self, server_name: Option<String>) -> Result {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[admin_command]
|
||||||
|
async fn flush_cache(&self, name: Option<OwnedServerName>, all: bool) -> Result {
|
||||||
|
if all {
|
||||||
|
self.services.resolver.cache.clear().await;
|
||||||
|
writeln!(self, "Resolver caches cleared!").await
|
||||||
|
} else if let Some(name) = name {
|
||||||
|
self.services.resolver.cache.del_destination(&name);
|
||||||
|
self.services.resolver.cache.del_override(&name);
|
||||||
|
self.write_str(&format!("Cleared {name} from resolver caches!"))
|
||||||
|
.await
|
||||||
|
} else {
|
||||||
|
Err!("Missing name. Supply a name or use --all to flush the whole cache.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user