Cache markdown and append realtime messages

This commit is contained in:
kris
2026-04-10 22:40:49 +08:00
parent 1b0f126d4f
commit 05dc9d8788
4 changed files with 161 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
async function readSource(path: string) {
return readFile(new URL(path, import.meta.url), "utf8");
}
test("ProjectDetailActivity keeps a rendered project snapshot for append-only realtime message patches", async () => {
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ProjectDetailActivity.java");
assert.match(
source,
/private @Nullable JSONObject currentRenderedProjectPayload;/,
"expected chat page to keep the latest rendered project payload for incremental realtime diffs",
);
assert.match(
source,
/if \(tryAppendRealtimeMessagesPatch\(projectMessagesPayload\)\) \{\s*return true;\s*\}/,
"expected chat page to try an append-only realtime patch before falling back to a full message rerender",
);
assert.match(
source,
/private boolean tryAppendRealtimeMessagesPatch\(JSONObject projectMessagesPayload\)/,
"expected chat page to expose a dedicated append-only realtime patch helper",
);
assert.match(
source,
/appendContent\(buildMessageView\(message\)\);/,
"expected append-only realtime patches to add only the new message views",
);
});

View File

@@ -0,0 +1,31 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
test("BossMarkdown caches rendered markdown spans for repeated bodies", async () => {
const source = await readFile(
new URL("../android/app/src/main/java/com/hyzq/boss/BossMarkdown.java", import.meta.url),
"utf8",
);
assert.match(
source,
/private static final LruCache<String, CharSequence> RENDER_CACHE = new LruCache<>\(/,
"expected markdown renderer to keep an LRU cache for rendered spans",
);
assert.match(
source,
/String cacheKey = buildCacheKey\(context, markdown, outgoing\);/,
"expected markdown renderer to derive a stable cache key before parsing",
);
assert.match(
source,
/CharSequence cached = RENDER_CACHE\.get\(cacheKey\);/,
"expected markdown renderer to reuse cached spans when available",
);
assert.match(
source,
/RENDER_CACHE\.put\(cacheKey, rendered\);/,
"expected markdown renderer to save rendered spans into the cache",
);
});