admin/maintenance: sqlite vacuum
This commit is contained in:
parent
ff6c910b2f
commit
37c5127bbc
6 changed files with 52 additions and 12 deletions
|
|
@ -536,6 +536,16 @@
|
||||||
},
|
},
|
||||||
"query": "update totp_login_requests\n\nset used_at = CURRENT_TIMESTAMP\n\nwhere token is ?"
|
"query": "update totp_login_requests\n\nset used_at = CURRENT_TIMESTAMP\n\nwhere token is ?"
|
||||||
},
|
},
|
||||||
|
"657fdc2b228b14a6aba717e5083daf48204274ab62d73ec8968bcd0c7568b157": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"nullable": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "vacuum"
|
||||||
|
},
|
||||||
"68cfa3d135eb4cdbdbcb3b943518b4ac09c371af689c444eb439a37f91ecf7a5": {
|
"68cfa3d135eb4cdbdbcb3b943518b4ac09c371af689c444eb439a37f91ecf7a5": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,15 @@ impl Settings {
|
||||||
.map_err(handle_error)
|
.map_err(handle_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn vacuum(conn: impl SqliteExecutor<'_>) -> Result<(), Error> {
|
||||||
|
sqlx::query!("vacuum")
|
||||||
|
.execute(conn)
|
||||||
|
.await
|
||||||
|
.map_err(handle_error)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn set_business_name(
|
pub async fn set_business_name(
|
||||||
conn: impl SqliteExecutor<'_>,
|
conn: impl SqliteExecutor<'_>,
|
||||||
value: Option<&str>,
|
value: Option<&str>,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ pub fn routes() -> Vec<Route> {
|
||||||
settings_security,
|
settings_security,
|
||||||
settings_security_form,
|
settings_security_form,
|
||||||
settings_maintenance,
|
settings_maintenance,
|
||||||
|
settings_maintenance_form,
|
||||||
admin_apps_list,
|
admin_apps_list,
|
||||||
admin_apps_new,
|
admin_apps_new,
|
||||||
admin_apps_new_form,
|
admin_apps_new_form,
|
||||||
|
|
|
||||||
|
|
@ -209,3 +209,29 @@ pub async fn settings_maintenance(
|
||||||
.map(|flash| Page::with_flash(page.clone(), flash))
|
.map(|flash| Page::with_flash(page.clone(), flash))
|
||||||
.unwrap_or_else(|| page.into()))
|
.unwrap_or_else(|| page.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, FromForm)]
|
||||||
|
pub struct CleanForm {
|
||||||
|
pub vacuum: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/admin/settings/maintenance", data = "<form>")]
|
||||||
|
pub async fn settings_maintenance_form(
|
||||||
|
mut db: Connection<Database>,
|
||||||
|
_admin: JwtAdmin,
|
||||||
|
form: Form<CleanForm>,
|
||||||
|
) -> Result<Flash<Redirect>> {
|
||||||
|
let (flash_kind, flash_message) = if matches!(form.vacuum, Some(true)) {
|
||||||
|
Settings::vacuum(&mut **db).await?;
|
||||||
|
|
||||||
|
(FlashKind::Success, "Database has been cleaned.")
|
||||||
|
} else {
|
||||||
|
(FlashKind::Warning, "Nothing to do.")
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Flash::new(
|
||||||
|
Redirect::to(uri!(settings_maintenance)),
|
||||||
|
flash_kind,
|
||||||
|
flash_message,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,17 +75,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>Do you want to clean the database?</h3>
|
<h3>Do you want to clean the database?</h3>
|
||||||
<div class="mt-2">
|
<div class="mt-2">This might take some time, but should not be long.</div>
|
||||||
This action will <strong>delete</strong> the following:
|
|
||||||
</div>
|
|
||||||
<ul class="list-inline mt-1">
|
|
||||||
<li>Authorization codes</li>
|
|
||||||
<li>Refresh tokens</li>
|
|
||||||
<li>TOTP requests</li>
|
|
||||||
</ul>
|
|
||||||
<div class="mt-2">
|
|
||||||
This action will be permanent.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -99,7 +89,7 @@
|
||||||
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<button type="submit" name="clean" value="true" class="btn btn-danger w-100">
|
<button type="submit" name="vacuum" value="true" class="btn btn-danger w-100">
|
||||||
Clean database
|
Clean database
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ impl Settings {
|
||||||
.map(human_bytes))
|
.map(human_bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn vacuum(conn: impl SqliteExecutor<'_>) -> Result<(), Error> {
|
||||||
|
Ok(DatabaseSettings::vacuum(conn).await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn set_business_name(
|
pub async fn set_business_name(
|
||||||
conn: impl SqliteExecutor<'_>,
|
conn: impl SqliteExecutor<'_>,
|
||||||
business_name: &str,
|
business_name: &str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue