Add gc command to clean up vault
This commit is contained in:
parent
099cb8d4f7
commit
4e014168b4
2 changed files with 17 additions and 0 deletions
|
|
@ -28,6 +28,8 @@ enum Command {
|
||||||
Run,
|
Run,
|
||||||
/// Export logs for a single room as a plain text file.
|
/// Export logs for a single room as a plain text file.
|
||||||
Export { room: String, file: PathBuf },
|
Export { room: String, file: PathBuf },
|
||||||
|
/// Compact and clean up vault.
|
||||||
|
Gc,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Command {
|
impl Default for Command {
|
||||||
|
|
@ -54,6 +56,11 @@ async fn main() -> anyhow::Result<()> {
|
||||||
match args.command.unwrap_or_default() {
|
match args.command.unwrap_or_default() {
|
||||||
Command::Run => run(&vault).await?,
|
Command::Run => run(&vault).await?,
|
||||||
Command::Export { room, file } => export::export(&vault, room, &file).await?,
|
Command::Export { room, file } => export::export(&vault, room, &file).await?,
|
||||||
|
Command::Gc => {
|
||||||
|
println!("Cleaning up and compacting vault");
|
||||||
|
println!("This may take a while...");
|
||||||
|
vault.gc().await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vault.close().await;
|
vault.close().await;
|
||||||
|
|
|
||||||
10
src/vault.rs
10
src/vault.rs
|
|
@ -13,6 +13,7 @@ pub use self::euph::{EuphMsg, EuphVault};
|
||||||
|
|
||||||
enum Request {
|
enum Request {
|
||||||
Close(oneshot::Sender<()>),
|
Close(oneshot::Sender<()>),
|
||||||
|
Gc(oneshot::Sender<()>),
|
||||||
Euph(EuphRequest),
|
Euph(EuphRequest),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,6 +29,12 @@ impl Vault {
|
||||||
let _ = rx.await;
|
let _ = rx.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn gc(&self) {
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
let _ = self.tx.send(Request::Gc(tx));
|
||||||
|
let _ = rx.await;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn euph(&self, room: String) -> EuphVault {
|
pub fn euph(&self, room: String) -> EuphVault {
|
||||||
EuphVault {
|
EuphVault {
|
||||||
tx: self.tx.clone(),
|
tx: self.tx.clone(),
|
||||||
|
|
@ -48,6 +55,9 @@ fn run(mut conn: Connection, mut rx: mpsc::UnboundedReceiver<Request>) {
|
||||||
drop(tx);
|
drop(tx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Request::Gc(tx) => {
|
||||||
|
let _ = conn.execute_batch("ANALYZE; VACUUM;");
|
||||||
|
}
|
||||||
Request::Euph(r) => r.perform(&mut conn),
|
Request::Euph(r) => r.perform(&mut conn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue