Skip to main content

tuwunel_admin/query/raw/
clear.rs

1use futures::{FutureExt, StreamExt};
2use tokio::time::Instant;
3use tuwunel_core::{Err, Result, utils::stream::TryIgnore};
4
5use crate::admin_command;
6
7#[admin_command]
8pub(super) async fn raw_clear(&self, map: String, confirm: bool) -> Result {
9	let map = self.services.db.get(&map)?;
10
11	if !confirm {
12		return Err!("Are you really sure you want to clear all data? Add the --confirm option.");
13	}
14
15	let timer = Instant::now();
16	let cork = self.services.db.cork();
17	let count = map
18		.raw_keys()
19		.ignore_err()
20		.map(|key| map.remove(&key))
21		.count()
22		.boxed()
23		.await;
24
25	drop(cork);
26	let query_time = timer.elapsed();
27	write!(self, "Operation completed in {query_time:?}\n\nremoved {count} keys\n").await
28}