mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-01 15:02:31 +00:00
fix(customisation-sync): stop truncating entry mtimes to 32 bits
PluginDataExDisplayV2.mtime applied `~~` to the sum of millisecond timestamps before dividing, which keeps only the low 32 bits. The freshness chip and "Select All Shiny" then compared wrapped values and could offer an older copy as newer. Fixes #1194
This commit is contained in:
@@ -52,7 +52,7 @@ vi.mock("@/common/obsidianCommunityPlugins.ts", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
import { cancelTask } from "@/common/utils.ts";
|
import { cancelTask } from "@/common/utils.ts";
|
||||||
import { ConfigSync } from "./CmdConfigSync";
|
import { ConfigSync, PluginDataExDisplayV2, type IPluginDataExDisplay } from "./CmdConfigSync";
|
||||||
|
|
||||||
describe("ConfigSync commands", () => {
|
describe("ConfigSync commands", () => {
|
||||||
it("shows the Customisation Sync command only whilst the feature is enabled", () => {
|
it("shows the Customisation Sync command only whilst the feature is enabled", () => {
|
||||||
@@ -111,3 +111,25 @@ describe("ConfigSync commands", () => {
|
|||||||
expect(periodicPluginSweepProcessor.disable).toHaveBeenCalledOnce();
|
expect(periodicPluginSweepProcessor.disable).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("PluginDataExDisplayV2", () => {
|
||||||
|
const entryWithModifiedTimes = (mtimes: number[]) =>
|
||||||
|
new PluginDataExDisplayV2({
|
||||||
|
documentPath: "ix:device/plugin_main/example",
|
||||||
|
category: "PLUGIN_MAIN",
|
||||||
|
name: "example",
|
||||||
|
term: "device",
|
||||||
|
files: mtimes.map((mtime, index) => ({ filename: `file-${index}`, mtime, data: [] })),
|
||||||
|
} as unknown as IPluginDataExDisplay);
|
||||||
|
|
||||||
|
it("averages millisecond modification times without truncating them to 32 bits", () => {
|
||||||
|
const mtime = Date.UTC(2026, 8, 15);
|
||||||
|
expect(entryWithModifiedTimes([mtime, mtime, mtime]).mtime).toBe(mtime);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps a newer copy newer than an older one", () => {
|
||||||
|
const newer = entryWithModifiedTimes([Date.UTC(2026, 8, 15)]);
|
||||||
|
const older = entryWithModifiedTimes([Date.UTC(2026, 8, 2)]);
|
||||||
|
expect(newer.mtime).toBeGreaterThan(older.mtime);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -368,7 +368,8 @@ export class PluginDataExDisplayV2 {
|
|||||||
return this._version;
|
return this._version;
|
||||||
}
|
}
|
||||||
get mtime(): number {
|
get mtime(): number {
|
||||||
return ~~this.files.reduce((a, b) => a + b.mtime, 0) / this.files.length;
|
// Millisecond timestamps exceed 32 bits, so `~~` would wrap them.
|
||||||
|
return Math.floor(this.files.reduce((a, b) => a + b.mtime, 0) / this.files.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export type PluginDataEx = {
|
export type PluginDataEx = {
|
||||||
|
|||||||
Reference in New Issue
Block a user