Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6f3a35d
chore(sync): record a full sync between two local instances
eliandoran Nov 29, 2026
7ae0fa1
chore(sync): trace a sync of a snapshot of an existing database
eliandoran Nov 29, 2026
903d013
perf(sync): download large blobs after the pull as raw bytes
eliandoran Nov 29, 2026
4249f74
chore(sync): show deferred blob downloads in sync traces
eliandoran Nov 29, 2026
97677c5
chore(sync): simulate a network link in sync traces
eliandoran Nov 29, 2026
185ac8f
perf(sync): download four deferred blobs at a time
eliandoran Nov 29, 2026
1318da5
perf(sync): ask for compressed sync responses over Node http
eliandoran Nov 29, 2026
df06ef4
perf(sync): skip compressing PNG, protected and ownerless blobs
eliandoran Nov 29, 2026
f99c72d
chore(sync): measure response encodings in sync traces
eliandoran Nov 29, 2026
6774299
feat(sync): type failed requests and time out stalled ones
eliandoran Nov 29, 2026
aee0f1b
fix(sync): keep downloading deferred blobs past one that fails
eliandoran Nov 29, 2026
2051d6d
chore(sync): profile both instances of a sync trace
eliandoran Nov 29, 2026
1ea143d
perf(sync): apply each pulled chunk while the next one downloads
eliandoran Nov 29, 2026
91d7473
perf(sync): read pulled rows with one query per table
eliandoran Nov 29, 2026
2a82c02
fix(sync): read pulled blob content only up to the response cap
eliandoran Nov 29, 2026
d6b06fd
perf(sync): send a blob's ID as its ETag
eliandoran Nov 29, 2026
72b36b1
perf(sync): decompress sync responses while they arrive
eliandoran Nov 29, 2026
66f4261
perf(sync): skip frontend updates during the initial sync
eliandoran Nov 29, 2026
0ca95e2
perf(sync): look up each pulled change's local version once
eliandoran Nov 29, 2026
029bfa7
perf(sync): send pulled text content as text instead of base64
eliandoran Nov 29, 2026
3f85812
perf(sync): hash local content while the server hashes its own
eliandoran Nov 29, 2026
cb60990
fix(sync): stop downloading blobs after failures in a row
eliandoran Nov 29, 2026
d507584
docs(sync): describe large files arriving after the initial sync
eliandoran Nov 29, 2026
f91a86b
feat(sync): send byte request bodies as they are
eliandoran Nov 29, 2026
6991f0e
fix(sync): push large attachments as raw bytes
eliandoran Nov 29, 2026
7f1db35
perf(sync): skip the content check when nothing changed
eliandoran Nov 29, 2026
873e008
fix(sync): retry deferred blobs a sync peer lacked
eliandoran Nov 29, 2026
17bc745
chore(sync-trace): refuse to replace an unrelated output directory
eliandoran Nov 29, 2026
d4e5a64
chore(sync): cover the remaining sync paths and tidy their code
eliandoran Nov 29, 2026
21bf746
fix(sync): keep a sector repair from emptying blobs
eliandoran Nov 29, 2026
0f43478
feat(sync): download a note's content when it is opened
eliandoran Nov 29, 2026
5461890
fix(sync): keep concurrent uploads of a blob apart
eliandoran Nov 29, 2026
4d47944
chore(sync): cover opening a stub note on the sync server
eliandoran Nov 29, 2026
17244a2
chore(sync): drop unreachable branches from sync requests
eliandoran Nov 29, 2026
6198710
chore(sync): cover the sync paths the coverage gate missed
eliandoran Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/20261129092610_sync-deferred-blobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: improvement
area: Sync
---

Setting up sync with a large knowledge base finishes sooner: large images and files are downloaded after the notes are ready to use.
6 changes: 6 additions & 0 deletions .changelog/20261129190718_sync-large-blob-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: fix
area: Sync
---

Attachments larger than about 384 MB could not be synchronized, and changes made after one never reached the sync server.
6 changes: 6 additions & 0 deletions .changelog/20261129193451_sync-stub-overwrite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: fix
area: Sync
---

Repairing a sync mismatch from a device that had not downloaded every large file could erase the content of those files on the sync server.
6 changes: 6 additions & 0 deletions .changelog/20261129193518_sync-download-on-open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: improvement
area: Sync
---

On the mobile app, opening a note whose content is over the sync size limit now downloads that content instead of only offering to open it on the sync server.
41 changes: 41 additions & 0 deletions apps/client/src/services/froca_updater.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,3 +884,44 @@ describe("froca_updater - note images", () => {
expect(getNoteImageSourceToLoad(src)).not.toBe(before);
});
});

describe("froca_updater - downloaded blobs", () => {
it("reloads the content of the notes and attachments that hold a downloaded blob", async () => {
const holder = buildNote({ title: "BlobHolder" });
const other = buildNote({ title: "OtherBlob" });
holder.blobId = "downloadedBlob";
const att = new FAttachment(froca, {
attachmentId: "att-downloaded",
ownerId: other.noteId,
role: "file",
mime: "application/pdf",
title: "a.pdf",
blobId: "downloadedBlob",
dateModified: "",
utcDateModified: "",
utcDateScheduledForErasureSince: "",
contentLength: 0
});
const cached = Promise.resolve(null);
froca.blobPromises[`notes-${holder.noteId}`] = cached;
froca.blobPromises[`notes-${other.noteId}`] = cached;
froca.blobPromises[`attachments-${att.attachmentId}`] = cached;

await frocaUpdater.processDownloadedBlob("downloadedBlob");

expect(Object.keys(froca.blobPromises)).not.toContain(`notes-${holder.noteId}`);
expect(Object.keys(froca.blobPromises)).not.toContain(`attachments-${att.attachmentId}`);
expect(froca.blobPromises[`notes-${other.noteId}`]).toBe(cached);
expect(triggerSpy).toHaveBeenCalledOnce();
const loadResults = triggerSpy.mock.calls[0][1].loadResults as LoadResults;
expect(loadResults.isNoteContentReloaded(holder.noteId, "anyComponent")).toBeTruthy();
expect(loadResults.isNoteContentReloaded(other.noteId, "anyComponent")).toBeFalsy();
delete froca.attachments[att.attachmentId];
});

it("sends no event for a blob no loaded note holds", async () => {
await frocaUpdater.processDownloadedBlob("unknownBlob");

expect(triggerSpy).not.toHaveBeenCalled();
});
});
31 changes: 30 additions & 1 deletion apps/client/src/services/froca_updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,34 @@ async function processEntityChanges(changes: EntityChange[]) {
}
}

/**
* Reloads the content of the notes and attachments whose blob `blobId` the backend has just
* downloaded from the sync server. Filling a stub changes no entity, so no entity change reports it.
*/
async function processDownloadedBlob(blobId: string) {
const loadResults = new LoadResults([]);
const noteIds: string[] = [];

for (const note of Object.values(froca.notes)) {
if (note.blobId === blobId) {
delete froca.blobPromises[`notes-${note.noteId}`];
loadResults.addNoteContent(note.noteId, "");
noteIds.push(note.noteId);
}
}
for (const attachment of Object.values(froca.attachments)) {
if (attachment.blobId === blobId) {
delete froca.blobPromises[`attachments-${attachment.attachmentId}`];
noteIds.push(attachment.ownerId);
}
}

invalidateNoteImages(noteIds);
if (!loadResults.isEmpty()) {
await appContext.triggerEvent("entitiesReloaded", { loadResults });
}
}

function processNoteChange(loadResults: LoadResults, ec: EntityChange) {
const note = froca.notes[ec.entityId];

Expand Down Expand Up @@ -379,5 +407,6 @@ function getImageNoteIds(entityChanges: EntityChange[]) {
}

export default {
processEntityChanges
processEntityChanges,
processDownloadedBlob
};
7 changes: 6 additions & 1 deletion apps/client/src/services/ws.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const toast = vi.hoisted(() => ({
const showUnhandledError = vi.hoisted(() => vi.fn());
const bundle = vi.hoisted(() => ({ getAndExecuteBundle: vi.fn() }));
const appCtx = vi.hoisted(() => ({ triggerEvent: vi.fn() }));
const frocaUpdater = vi.hoisted(() => ({ processEntityChanges: vi.fn(async () => {}) }));
const frocaUpdater = vi.hoisted(() => ({ processEntityChanges: vi.fn(async () => {}), processDownloadedBlob: vi.fn(async () => {}) }));
const utilsCtrl = vi.hoisted(() => ({
reloadFrontendApp: vi.fn(),
timeLimit: vi.fn(async (p: Promise<unknown>, _ms?: number) => p)
Expand Down Expand Up @@ -99,6 +99,11 @@ describe("dispatchMessage", () => {
await ws.dispatchMessage({ type: "consistency-checks-failed" } as any);
expect(toast.showError).toHaveBeenCalledTimes(1);

// Only a downloaded blob reloads content; the stub placeholder handles the other outcomes.
await ws.dispatchMessage({ type: "blob-download", blobId: "b1", outcome: "failed" });
await ws.dispatchMessage({ type: "blob-download", blobId: "b1", outcome: "downloaded" });
expect(frocaUpdater.processDownloadedBlob.mock.calls).toEqual([ [ "b1" ] ]);

await ws.dispatchMessage({ type: "api-log-messages", noteId: "n1", messages: ["a"] } as any);
expect(appCtx.triggerEvent).toHaveBeenCalledWith("apiLogMessages", { noteId: "n1", messages: ["a"] });

Expand Down
4 changes: 4 additions & 0 deletions apps/client/src/services/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export async function dispatchMessage(message: WebSocketMessage) {
t("ws.sync-hash-check-failed", { sectors: (msg.sectors ?? []).join(", ") }),
50 * 60000
);
} else if (messageType === "blob-download") {
if (msg.outcome === "downloaded") {
await frocaUpdater.processDownloadedBlob(msg.blobId);
}
} else if (messageType === "consistency-checks-failed") {
toastService.showError(t("ws.consistency-checks-failed"), 50 * 60000);
} else if (messageType === "api-log-messages") {
Expand Down
7 changes: 5 additions & 2 deletions apps/client/src/translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,11 @@
"enter_workspace": "Enter workspace {{title}}"
},
"blob_stub": {
"not_synced": "This note's content is too large to sync to this device. You can open it on the sync server instead.",
"open_on_server": "Open on server"
"not_synced": "This note's content has not reached this device, and the sync server could not provide it. You can open it on the sync server instead.",
"open_on_server": "Open on server",
"downloading": "Downloading this note's content from the sync server...",
"download_failed": "This note's content could not be downloaded from the sync server. You can try again, or open it on the sync server instead.",
"try_again": "Try again"
},
"file": {
"file_preview_not_available": "File preview is not available for this file format.",
Expand Down
10 changes: 7 additions & 3 deletions apps/client/src/widgets/type_widgets/BlobStub.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
gap: 1em;
padding: 2em;
text-align: center;
}

.note-detail-blob-stub button {
margin-top: 0.5em;
.blob-stub-actions {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.5em;
margin-top: 0.5em;
}
}
134 changes: 134 additions & 0 deletions apps/client/src/widgets/type_widgets/BlobStub.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import type { WebSocketMessage } from "@triliumnext/commons";
import { render } from "preact";
import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

const { post, processDownloadedBlob, handlers } = vi.hoisted(() => ({
post: vi.fn(),
processDownloadedBlob: vi.fn(async () => {}),
handlers: new Set<(message: WebSocketMessage) => void>()
}));

vi.mock("../../services/server", () => ({ default: { post, get: vi.fn(async () => []) } }));
vi.mock("../../services/i18n", () => ({ t: (key: string) => key }));
vi.mock("../../services/froca_updater", () => ({ default: { processDownloadedBlob } }));
vi.mock("../../services/ws", () => ({
subscribeToMessages: (handler: (message: WebSocketMessage) => void) => handlers.add(handler),
unsubscribeToMessage: (handler: (message: WebSocketMessage) => void) => handlers.delete(handler)
}));

import type FNote from "../../entities/fnote";
import options from "../../services/options";
import BlobStub from "./BlobStub";
import type { TypeWidgetProps } from "./type_widget";

const container = document.createElement("div");
document.body.appendChild(container);
const note = { noteId: "stubNote", blobId: "stubBlob" } as FNote;

async function mount() {
await act(async () => render(<BlobStub {...{ note, ntxId: "pane", noteContext: undefined } as unknown as TypeWidgetProps} />, container));
}

async function send(message: WebSocketMessage) {
await act(async () => {
for (const handler of handlers) {
handler(message);
}
});
}

const text = () => container.querySelector(".note-detail-blob-stub")?.textContent ?? "";
const buttons = () => [ ...container.querySelectorAll("button") ].map((button) => button.textContent?.trim());

beforeEach(() => {
post.mockReset();
options.set("syncServerHost", "");
});

afterEach(async () => {
await act(async () => render(null, container));
});

describe("BlobStub", () => {
it("downloads the content at once and shows that it is downloading", async () => {
post.mockResolvedValue({ status: "downloading" });

await mount();

expect(post).toHaveBeenCalledWith("sync/download-blob/stubBlob");
expect(text()).toContain("blob_stub.downloading");
expect(buttons()).toEqual([]);

// Another blob's outcome leaves this one downloading.
await send({ type: "blob-download", blobId: "otherBlob", outcome: "failed" });
expect(text()).toContain("blob_stub.downloading");
});

it("offers to try again after a failed download, and downloads again", async () => {
post.mockResolvedValue({ status: "downloading" });
await mount();

await send({ type: "blob-download", blobId: "stubBlob", outcome: "failed" });
expect(text()).toContain("blob_stub.download_failed");
const tryAgain = [ ...container.querySelectorAll("button") ].find((button) => button.textContent?.trim() === "blob_stub.try_again");
expect(tryAgain).toBeDefined();

await act(async () => tryAgain?.click());
expect(post).toHaveBeenCalledTimes(2);
expect(text()).toContain("blob_stub.downloading");
});

it("says the content is not available when the sync server has none, or there is no sync server", async () => {
post.mockResolvedValue({ status: "downloading" });
await mount();
await send({ type: "blob-download", blobId: "stubBlob", outcome: "unavailable" });
expect(text()).toContain("blob_stub.not_synced");
expect(buttons()).not.toContain("blob_stub.try_again");

await act(async () => render(null, container));
post.mockResolvedValue({ status: "unavailable" });
await mount();
expect(text()).toContain("blob_stub.not_synced");
});

it("opens the note on the sync server", async () => {
options.set("syncServerHost", "https://sync.example.com//");
const open = vi.spyOn(window, "open").mockImplementation(() => null);
post.mockResolvedValue({ status: "unavailable" });
await mount();

const openOnServer = [ ...container.querySelectorAll("button") ].find((button) => button.textContent?.trim() === "blob_stub.open_on_server");
expect(openOnServer).toBeDefined();
await act(async () => openOnServer?.click());

expect(open).toHaveBeenCalledWith("https://sync.example.com/#root/stubNote", "_blank", "noopener,noreferrer");
open.mockRestore();
});

it("treats a failed request as a failed download", async () => {
post.mockRejectedValue(new Error("offline"));

await mount();

expect(text()).toContain("blob_stub.download_failed");
});

it("reloads the note when its content arrived before the request", async () => {
post.mockResolvedValue({ status: "downloaded" });

await mount();

expect(processDownloadedBlob).toHaveBeenCalledWith("stubBlob");
});

it("stops listening once removed", async () => {
post.mockResolvedValue({ status: "downloading" });
await mount();
expect(handlers.size).toBe(1);

await act(async () => render(null, container));

expect(handlers.size).toBe(0);
});
});
Loading
Loading