Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
feat: vacuum database in setting (#694)
Zeng1998147185309c19
diff --git a/server/system.go b/server/system.goindex 6c08a3bef..6d493691c 100644--- a/server/system.go+++ b/server/system.go@@ -148,4 +148,26 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {}return nil})++ g.POST("/system/vacuum", func(c echo.Context) error {+ ctx := c.Request().Context()+ userID, ok := c.Get(getUserIDContextKey()).(int)+ if !ok {+ return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")+ }+ user, err := s.Store.FindUser(ctx, &api.UserFind{+ ID: &userID,+ })+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)+ }+ if user == nil || user.Role != api.Host {+ return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")+ }+ if err := s.Store.Vacuum(ctx); err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to vacuum database").SetInternal(err)+ }+ c.Response().WriteHeader(http.StatusOK)+ return nil+ })}diff --git a/web/src/components/Settings/SystemSection.tsx b/web/src/components/Settings/SystemSection.tsxindex 8184f17db..94c050534 100644--- a/web/src/components/Settings/SystemSection.tsx+++ b/web/src/components/Settings/SystemSection.tsx@@ -60,6 +60,23 @@ const SystemSection = () => {});};+ const handleVacuumBtnClick = async () => {+ try {+ await api.vacuumDatabase();+ const { data: status } = (await api.getSystemStatus()).data;+ setState({+ dbSize: status.dbSize,+ allowSignUp: status.allowSignUp,+ additionalStyle: status.additionalStyle,+ additionalScript: status.additionalScript,+ });+ } catch (error) {+ console.error(error);+ return;+ }+ toastHelper.success("Succeed to vacuum database");+ };+const handleSaveAdditionalStyle = async () => {try {await api.upsertSystemSetting({@@ -96,9 +113,14 @@ const SystemSection = () => {return (<div className="section-container system-section-container"><p className="title-text">{t("common.basic")}</p>- <p className="text-value">- {t("setting.system-section.database-file-size")}: <span className="font-mono font-medium">{formatBytes(state.dbSize)}</span>- </p>+ <label className="form-label">+ <span className="normal-text">+ {t("setting.system-section.database-file-size")}: <span className="font-mono font-medium">{formatBytes(state.dbSize)}</span>+ </span>+ <Button size="sm" onClick={handleVacuumBtnClick}>+ {t("common.vacuum")}+ </Button>+ </label><p className="title-text">{t("sidebar.setting")}</p><label className="form-label"><span className="normal-text">{t("setting.system-section.allow-user-signup")}</span>diff --git a/web/src/helpers/api.ts b/web/src/helpers/api.tsindex 822f6049e..9fd11f030 100644--- a/web/src/helpers/api.ts+++ b/web/src/helpers/api.ts@@ -14,6 +14,10 @@ export function upsertSystemSetting(systemSetting: SystemSetting) {return axios.post<ResponseObject<SystemSetting>>("/api/system/setting", systemSetting);}+export function vacuumDatabase() {+ return axios.post("/api/system/vacuum");+}+export function signin(username: string, password: string) {return axios.post<ResponseObject<User>>("/api/auth/signin", {username,diff --git a/web/src/locales/de.json b/web/src/locales/de.jsonindex d96b6de53..b38c52d7e 100644--- a/web/src/locales/de.json+++ b/web/src/locales/de.json@@ -45,7 +45,8 @@"fold": "Falten","expand": "Erweitern","image": "Bild",- "link": "Link"+ "link": "Link",+ "vacuum": "Vacuum"},"slogan": "Eine quelloffene, selbst gehostete Sammlung an Memos zur Wissensverwaltung und Vernetzung.","auth": {diff --git a/web/src/locales/en.json b/web/src/locales/en.jsonindex 0619ae10e..31feb01dd 100644--- a/web/src/locales/en.json+++ b/web/src/locales/en.json@@ -45,7 +45,8 @@"fold": "Fold","expand": "Expand","image": "Image",- "link": "Link"+ "link": "Link",+ "vacuum": "Vacuum"},"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.","auth": {diff --git a/web/src/locales/fr.json b/web/src/locales/fr.jsonindex 3fd1ee92f..9e4dbba4f 100644--- a/web/src/locales/fr.json+++ b/web/src/locales/fr.json@@ -45,7 +45,8 @@"fold": "Plier","expand": "Développer","image": "Image",- "link": "Link"+ "link": "Link",+ "vacuum": "Vacuum"},"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.","auth": {diff --git a/web/src/locales/nl.json b/web/src/locales/nl.jsonindex d179cd2d5..5c21e5ee9 100644--- a/web/src/locales/nl.json+++ b/web/src/locales/nl.json@@ -41,7 +41,8 @@"changed": "gewijzigd","update-on": "Update op","fold": "Invouwen",- "expand": "Uitklappen"+ "expand": "Uitklappen",+ "vacuum": "Vacuum"},"slogan": "Een open-source, zelf-beheerd memo applicatie voor kennismanagement en collaboratie.","auth": {diff --git a/web/src/locales/sv.json b/web/src/locales/sv.jsonindex 0d2988d14..dcb4e1908 100644--- a/web/src/locales/sv.json+++ b/web/src/locales/sv.json@@ -45,7 +45,8 @@"fold": "Vik ihop","expand": "Expandera","image": "Bild",- "link": "Länk"+ "link": "Länk",+ "vacuum": "Vacuum"},"slogan": "En öppen källkod, self-hosted antecknings hubb med kunskapshantering och socialisering","auth": {diff --git a/web/src/locales/vi.json b/web/src/locales/vi.jsonindex 41c9fdacb..88a2705b6 100644--- a/web/src/locales/vi.json+++ b/web/src/locales/vi.json@@ -45,7 +45,8 @@"fold": "Fold","expand": "Expand","image": "Image",- "link": "Link"+ "link": "Link",+ "vacuum": "Vacuum"},"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.","auth": {diff --git a/web/src/locales/zh.json b/web/src/locales/zh.jsonindex 71762c195..7d6f3b592 100644--- a/web/src/locales/zh.json+++ b/web/src/locales/zh.json@@ -45,7 +45,8 @@"fold": "折叠","expand": "展开","image": "图片",- "link": "链接"+ "link": "链接",+ "vacuum": "清理"},"slogan": "An open-source, self-hosted memo hub with knowledge management and socialization.","auth": {