Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager/space usage: show the note revisions as a treemap bucket

Adorian Doran3c94ce79f638
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css
index b92634ee69..b4235d561c 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css
@@ -63,6 +63,7 @@
.space-usage-overview {
.treemap-cell.treemap-cell-other,
.treemap-cell.treemap-cell-hidden,
+ .treemap-cell.treemap-cell-revisions,
.treemap-cell.treemap-cell-deleted {
--treemap-cell-background: repeating-linear-gradient(
-45deg,
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.spec.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.spec.tsx
index 5dc0284d0a..4dec093760 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.spec.tsx
@@ -36,7 +36,7 @@ vi.mock("../../../../../services/froca", () => ({
import Overview from "./overview";
const OVERVIEW: SpaceUsageOverviewResponse = {
- content: { size: 400, noteCount: 3, attachmentsSize: 0, revisionsSize: 0 },
+ content: { size: 400, noteCount: 3, attachmentsSize: 0, revisionsSize: 60 },
notes: [ { noteId: "n1", notePath: [ "n1" ], ownSize: 200, attachmentsSize: 0, revisionsSize: 0 } ],
otherNotes: { size: 50, revisionsSize: 0, noteCount: 2 },
hiddenNotes: { size: 80, revisionsSize: 0, noteCount: 10 },
@@ -64,12 +64,13 @@ afterEach(() => {
});
describe("Overview", () => {
- it("renders a cell per note plus the three bucket cells", () => {
+ it("renders a cell per note plus the four bucket cells", () => {
const probe = renderOverview();
expect(probe.querySelector('[data-href="#root/n1"]')).not.toBeNull();
expect(probe.querySelector(".treemap-cell-other")).not.toBeNull();
expect(probe.querySelector(".treemap-cell-hidden")).not.toBeNull();
+ expect(probe.querySelector(".treemap-cell-revisions")).not.toBeNull();
expect(probe.querySelector(".treemap-cell-deleted")).not.toBeNull();
});
@@ -83,6 +84,7 @@ describe("Overview", () => {
expect(iconIn(".treemap-cell-other")).toContain("bx-dots-horizontal-rounded");
expect(iconIn(".treemap-cell-hidden")).toContain("bx-hide");
+ expect(iconIn(".treemap-cell-revisions")).toContain("bx-history");
expect(iconIn(".treemap-cell-deleted")).toContain("bx-trash-alt");
});
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx
index 285295f40d..ddf68e454b 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx
@@ -37,6 +37,9 @@ export default function Overview({ overview, onShowDetails }: OverviewProps) {
t("space_usage.hidden_notes", { count: overview.hiddenNotes.noteCount }),
bucketWeight(overview.hiddenNotes, INCLUDE_REVISIONS)
),
+ // Not a crowd of notes but a tier of content, so it names itself rather than a count — and
+ // the figure is the deduplicated one the status line quotes, which is what its cell draws.
+ revisionsLabel: withSize(t("space_usage.revisions"), overview.content.revisionsSize),
deletedNotesLabel: withSize(
t("space_usage.deleted_notes", { count: overview.deletedNotes.noteCount }),
overview.deletedNotes.size
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts
index 0e50bc7372..5fb9a8da83 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts
@@ -24,6 +24,7 @@ function build(overview: SpaceUsageOverviewResponse, includeRevisions = false) {
return buildOverviewModel(overview, {
otherNotesLabel: "Other notes",
hiddenNotesLabel: "Hidden notes",
+ revisionsLabel: "Revisions",
deletedNotesLabel: "Deleted notes",
includeRevisions,
makeSizeDetail: (size, attachmentsSize) => `size:${size}/att:${attachmentsSize}`
@@ -72,6 +73,7 @@ describe("buildOverviewModel", () => {
const silent = buildOverviewModel(overview, {
otherNotesLabel: "Other notes",
hiddenNotesLabel: "Hidden notes",
+ revisionsLabel: "Revisions",
deletedNotesLabel: "Deleted notes",
includeRevisions: true
});
@@ -99,6 +101,7 @@ describe("buildOverviewModel", () => {
{
otherNotesLabel: "Other notes",
hiddenNotesLabel: "Hidden notes",
+ revisionsLabel: "Revisions",
deletedNotesLabel: "Deleted notes",
includeRevisions: false,
getIcon: (noteId) => noteId === "parent" ? "tn-icon bx bx-folder" : undefined
@@ -180,6 +183,27 @@ describe("buildOverviewModel", () => {
expect(deleted.icon).toBe("bx bx-trash-alt");
});
+ it("sizes the revisions bucket from the deduplicated content tier, not the per-note figures", () => {
+ const model = build(response(
+ // Per-note revision sizes count each blob again at every entity sharing it, so they add
+ // up to far more than the database spent — the bucket must ignore them entirely.
+ [ entry("a", [ "a" ], { ownSize: 5, revisionsSize: 900 }) ],
+ {
+ content: { size: 60, noteCount: 1, attachmentsSize: 0, revisionsSize: 40 },
+ hiddenNotes: { size: 0, revisionsSize: 700, noteCount: 2 }
+ }
+ ));
+
+ const revisions = childById(model, "/revisions");
+ expect(revisions.value).toBe(40);
+ expect(revisions.className).toBe("treemap-cell-revisions");
+ expect(revisions.icon).toBe("bx bx-history");
+ expect(revisions.tooltip).toBe("Revisions");
+ // Inert like the other buckets: history is not a note to preview or open.
+ expect(revisions.data).toEqual({});
+ expect(revisions.attributes).toBeUndefined();
+ });
+
it("places an entry for the root itself as a top-level cell", () => {
const model = build(response([ entry("root", [], { ownSize: 9 }) ]));
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts
index 3149d026fc..c175ad9824 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts
@@ -14,6 +14,7 @@ export interface OverviewCell {
interface OverviewModelOptions {
otherNotesLabel: string;
hiddenNotesLabel: string;
+ revisionsLabel: string;
deletedNotesLabel: string;
/** Folds revision sizes into each cell's weight. */
includeRevisions: boolean;
@@ -35,15 +36,18 @@ interface OverviewModelOptions {
* location, pass-through ancestors shaping the layout without drawing anything, so large notes
* appear near their siblings and share their parent's hue. An entry that is itself an ancestor of
* other entries keeps its own weight as a nested self-cell inside its area. The "other notes",
- * "hidden notes" and "deleted notes" buckets join at the top level as inert cells, so every byte
- * the status line counts has a cell somewhere.
+ * "hidden notes", "revisions" and "deleted notes" buckets join at the top level as inert cells, so
+ * every byte the status line counts has a cell somewhere.
*
* The cells carry no text — identity comes from hovering: note cells get the note preview tooltip
* via `data-href`, the bucket cells the chart's own tooltip naming the crowd they stand for.
*/
export function buildOverviewModel(
overview: SpaceUsageOverviewResponse,
- { otherNotesLabel, hiddenNotesLabel, deletedNotesLabel, includeRevisions, getIcon, makeSizeDetail }: OverviewModelOptions
+ {
+ otherNotesLabel, hiddenNotesLabel, revisionsLabel, deletedNotesLabel,
+ includeRevisions, getIcon, makeSizeDetail
+ }: OverviewModelOptions
): TreemapItem<OverviewCell> {
const root: TreemapItem<OverviewCell> = { id: "root", children: [] };
const nodesByNoteId = new Map<string, TreemapItem<OverviewCell>>();
@@ -132,6 +136,17 @@ export function buildOverviewModel(
tooltip: hiddenNotesLabel,
data: {}
},
+ {
+ // The deduplicated tier from the content totals, never a sum of the per-note figures:
+ // those count a revision's blob again at each entity that shares it, so summing them
+ // would give the map an area the database never spent.
+ id: "/revisions",
+ value: overview.content.revisionsSize,
+ className: "treemap-cell-revisions",
+ icon: "bx bx-history",
+ tooltip: revisionsLabel,
+ data: {}
+ },
{
id: "/deleted-notes",
value: overview.deletedNotes.size,