Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/options: add an option to keep named revisions
Adorian Doran5cba29ad0ff7
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f444cd26eb..06c892d527 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1857,6 +1857,8 @@"note_revisions_snapshot_limit_description_short": "Max revisions per note. Use -1 for unlimited, 0 to disable.","snapshot_number_limit_label": "Maximum revisions","snapshot_number_limit_unit": "snapshots",+ "keep_named_revisions_label": "Keep named revisions",+ "keep_named_revisions_description": "Revisions you have named are never erased and don't count towards the maximum.","erase_excess_revision_snapshots": "Erase excess revision snapshots","erase_excess_revision_snapshots_description": "Delete revisions exceeding the limit for all notes.","erase_now_button": "Erase now",diff --git a/apps/client/src/widgets/type_widgets/options/other.tsx b/apps/client/src/widgets/type_widgets/options/other.tsxindex 930f9fb52b..be2e687818 100644--- a/apps/client/src/widgets/type_widgets/options/other.tsx+++ b/apps/client/src/widgets/type_widgets/options/other.tsx@@ -108,6 +108,7 @@ function AttachmentErasureTimeout() {function RevisionSettings() {const [ revisionSnapshotNumberLimit, setRevisionSnapshotNumberLimit ] = useTriliumOption("revisionSnapshotNumberLimit");+ const [ revisionIgnoreNamedSnapshots, setRevisionIgnoreNamedSnapshots ] = useTriliumOptionBool("revisionIgnoreNamedSnapshots");return (<OptionsSection title={t("revisions_snapshot.title")}>@@ -133,6 +134,14 @@ function RevisionSettings() {/></OptionsRow>+ <OptionsRowWithToggle+ name="revision-keep-named-snapshots"+ label={t("revisions_snapshot_limit.keep_named_revisions_label")}+ description={t("revisions_snapshot_limit.keep_named_revisions_description")}+ currentValue={revisionIgnoreNamedSnapshots}+ onChange={setRevisionIgnoreNamedSnapshots}+ />+<OptionsRowWithButtonlabel={t("revisions_snapshot_limit.erase_excess_revision_snapshots")}description={t("revisions_snapshot_limit.erase_excess_revision_snapshots_description")}diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.tsindex f709799646..f7c3e86e3d 100644--- a/packages/commons/src/lib/options_interface.ts+++ b/packages/commons/src/lib/options_interface.ts@@ -109,6 +109,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActirevisionSnapshotTimeInterval: number;revisionSnapshotTimeIntervalTimeScale: number;revisionSnapshotNumberLimit: number;+ revisionIgnoreNamedSnapshots: boolean;protectedSessionTimeout: number;protectedSessionTimeoutTimeScale: number;zoomFactor: number;diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 9896f1cf04..58552359f5 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -75,7 +75,8 @@ export interface EraseExcessRevisionsOptions {snapshotsToKeep?: number;/*** Spares named snapshots — those the user gave a description — from erasure, and leaves them- * out of the count as well, so the limit governs the automatic snapshots alone.+ * out of the count as well, so the limit governs the automatic snapshots alone. Omitted, it+ * falls back to the `revisionIgnoreNamedSnapshots` option.*/keepNamedSnapshots?: boolean;}diff --git a/packages/trilium-core/src/becca/entities/bnote.ts b/packages/trilium-core/src/becca/entities/bnote.tsindex fdaede56a5..e1beb36804 100644--- a/packages/trilium-core/src/becca/entities/bnote.ts+++ b/packages/trilium-core/src/becca/entities/bnote.ts@@ -1619,7 +1619,8 @@ class BNote extends AbstractBeccaEntity<BNote> {// of the reckoning entirely: they are neither erased nor counted, and the limit then// governs the automatic snapshots alone. Counting them would let a handful of named ones// push every automatic snapshot out.- const candidates = keepNamedSnapshots+ const keepNamed = keepNamedSnapshots ?? optionService.getOptionBool("revisionIgnoreNamedSnapshots");+ const candidates = keepNamed? this.getRevisions().filter((revision) => !revision.description): this.getRevisions();diff --git a/packages/trilium-core/src/becca/entities/bnote_content.spec.ts b/packages/trilium-core/src/becca/entities/bnote_content.spec.tsindex 1112be89c7..fe413928e8 100644--- a/packages/trilium-core/src/becca/entities/bnote_content.spec.ts+++ b/packages/trilium-core/src/becca/entities/bnote_content.spec.ts@@ -595,6 +595,19 @@ describe("BNote content / misc getters", () => {expect(eraseExcess(note, { snapshotsToKeep: 1 })).toBe(4);expect(revisionIdsOf(note)).toEqual([ newest ]);});++ it("spares named snapshots by the configured option when the caller says nothing", () => {+ const note = createNote();+ const [ , named, newest ] = createRevisions(note, [ undefined, "release", undefined ]);+ getContext().init(() => optionService.setOption("revisionIgnoreNamedSnapshots", "true"));++ try {+ expect(eraseExcess(note, { snapshotsToKeep: 1 })).toBe(1);+ expect(revisionIdsOf(note)).toEqual([ named, newest ]);+ } finally {+ getContext().init(() => optionService.setOption("revisionIgnoreNamedSnapshots", "false"));+ }+ });});describe("saveAttachment matchBy (lines 1628-1655)", () => {diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.tsindex 7949819618..4e590647f6 100644--- a/packages/trilium-core/src/routes/api/options.ts+++ b/packages/trilium-core/src/routes/api/options.ts@@ -29,6 +29,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>(["revisionSnapshotTimeInterval","revisionSnapshotTimeIntervalTimeScale","revisionSnapshotNumberLimit",+ "revisionIgnoreNamedSnapshots","zoomFactor","theme","codeBlockTheme",diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.tsindex 68733c420a..5799c0c93b 100644--- a/packages/trilium-core/src/services/options_init.ts+++ b/packages/trilium-core/src/services/options_init.ts@@ -149,6 +149,7 @@ const defaultOptions: DefaultOption[] = [{ name: "revisionSnapshotTimeInterval", value: "600", isSynced: true },{ name: "revisionSnapshotTimeIntervalTimeScale", value: "60", isSynced: true }, // default to Minutes{ name: "revisionSnapshotNumberLimit", value: "-1", isSynced: true },+ { name: "revisionIgnoreNamedSnapshots", value: "false", isSynced: true },{ name: "protectedSessionTimeout", value: "600", isSynced: true },{ name: "protectedSessionTimeoutTimeScale", value: "60", isSynced: true },{ name: "zoomFactor", value: () => isWindows() ? "0.9" : "1.0", isSynced: false },