gui: the Sessions page draws its folders 100 at a time, so thousands of one-session folders don't hold every click (yetone)
An app that runs Codex once per picture, each in a folder of its own,
left 11,358 Codex folders of one session each on the owner's machine.
The page paged the sessions inside a folder (100 at a time) but drew
every folder: 113,900 elements. In WebKit a click to Sessions held the
main thread up to 2.7s, and since the hidden page stayed in the
document, a click to Library after it took ~240ms instead of ~40ms.
The folders are now drawn a page at a time like a folder's sessions:
the first 100, and a "Show N more folders" that adds the next 100 above
itself without redrawing or moving what is drawn (data-unrolls, as
moreRow). How many are drawn is kept in drawnIn, so it starts again at
a page wherever a folder's sessions do (another agent, the filter), and
unfolding a folder or coming back to the page keeps it. A session
opened from the Usage page has its folder drawn however far down it
is. The bar and a folder's box still pick every session, drawn or not.
New string in zh, zh-TW, ja and de.
Run:
- On the owner's real data (dev backend, 11,584 Codex sessions), WebKit,
this branch's assets vs main's: Sessions 113,900 -> 1,101 elements,
worst main-thread stall 2,675ms -> 44ms; Library click 238ms -> 32-62ms.
- New sessions-folder-paging.test.cjs: 10/10 (chromium + webkit, en, zh,
zh-TW, ja, de, 1000px and 380px). Drawing every folder again turns it
red (expected 100, actual 250).
- Every sessions GUI file (23): all pass except routing-sessions webkit
en, red the same alone on origin/main d9bb0fbc8 (#1672, noted there),
and session-identity once under the back-to-back run, 10/10 alone on
both (noted on #1544).
- go test ./internal/gui: ok.
This commit is contained in:
@@ -418,6 +418,7 @@ const I18N = {
|
||||
"No agents found": "没有找到 Agent",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "安装 Claude Code、Codex、Gemini CLI、OpenCode 等之后,会列在这里。",
|
||||
"Show {n} more": "显示其余 {n} 个",
|
||||
"Show {n} more folders": "显示其余 {n} 个文件夹",
|
||||
"Show less": "收起",
|
||||
"Expand the list": "展开列表",
|
||||
"Collapse the list": "收起列表",
|
||||
@@ -4880,6 +4881,7 @@ const I18N = {
|
||||
"No agents found": "沒有找到 Agent",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "安裝 Claude Code、Codex、Gemini CLI、OpenCode 等之後,會列在這裡。",
|
||||
"Show {n} more": "顯示其餘 {n} 個",
|
||||
"Show {n} more folders": "顯示其餘 {n} 個資料夾",
|
||||
"Show less": "收起",
|
||||
"Expand the list": "展開列表",
|
||||
"Collapse the list": "收起列表",
|
||||
@@ -9306,6 +9308,7 @@ const I18N = {
|
||||
"No agents found": "エージェントが見つかりません",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "Claude Code、Codex、Gemini CLI、OpenCode… をインストールすると、magpie がここに表示します。",
|
||||
"Show {n} more": "さらに {n} 件表示",
|
||||
"Show {n} more folders": "さらに {n} 個のフォルダを表示",
|
||||
"Show less": "表示を減らす",
|
||||
"Expand the list": "リストを広げる",
|
||||
"Collapse the list": "リストを畳む",
|
||||
@@ -13750,6 +13753,7 @@ const I18N = {
|
||||
"No agents found": "Keine Agenten gefunden",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "Installieren Sie Claude Code, Codex, Gemini CLI, OpenCode…, dann listet magpie sie hier auf.",
|
||||
"Show {n} more": "{n} weitere anzeigen",
|
||||
"Show {n} more folders": "{n} weitere Ordner anzeigen",
|
||||
"Show less": "Weniger anzeigen",
|
||||
"Expand the list": "Liste aufklappen",
|
||||
"Collapse the list": "Liste einklappen",
|
||||
|
||||
@@ -47,6 +47,12 @@
|
||||
// page when the agent or the filter changes.
|
||||
const SM_PAGE = 100;
|
||||
const drawnIn = new Map();
|
||||
// The folders are drawn a page at a time too, under FOLDERS in drawnIn:
|
||||
// an app that runs Codex once per picture in a folder of its own left
|
||||
// 11,358 folders of one session each, and drawing them all made 114,000
|
||||
// elements, held every click on the page for over a second, and slowed
|
||||
// the Library page after it (yetone).
|
||||
const FOLDERS = "\x00folders";
|
||||
|
||||
// A session seen only through magpie's gateway has no folder magpie knows
|
||||
// (its agent's files are on another computer, in a container or under
|
||||
@@ -551,55 +557,84 @@
|
||||
return;
|
||||
}
|
||||
const q = query.trim();
|
||||
for (const [cwd, items] of groups) {
|
||||
const open = !!q || opened.has(cwd);
|
||||
const g = el("div", "list sm-group");
|
||||
const r = el("div", "row sm-folder");
|
||||
const writable = items.filter((s) => s.deletable);
|
||||
// the folder's box picks every session of it shown, folded or not,
|
||||
// for the bar's Delete; the bar still counts sessions (#527)
|
||||
if (current()?.deletable && writable.length) {
|
||||
const c = el("input", "sm-check sm-folder-check");
|
||||
c.type = "checkbox";
|
||||
// a session's own box ticked or not shows here at once
|
||||
c.sync = () => {
|
||||
c.checked = writable.every((s) => picked.has(s.id));
|
||||
c.indeterminate = !c.checked && writable.some((s) => picked.has(s.id));
|
||||
};
|
||||
c.sync();
|
||||
folderBoxes.set(cwd, c);
|
||||
c.setAttribute("aria-label", t("Select every session in {folder}", { folder: groupName(cwd) }));
|
||||
c.onclick = (e) => e.stopPropagation();
|
||||
c.onchange = () => {
|
||||
for (const s of writable) c.checked ? picked.add(s.id) : picked.delete(s.id);
|
||||
redrawList();
|
||||
};
|
||||
r.append(c);
|
||||
}
|
||||
const fold = el("button", "fold");
|
||||
fold.type = "button";
|
||||
fold.setAttribute("aria-expanded", String(open));
|
||||
fold.append(svg(CHEV_R, 10, 1.6), el("span", "name", groupName(cwd)));
|
||||
fold.onclick = () => {
|
||||
if (opened.has(cwd)) opened.delete(cwd); else opened.add(cwd);
|
||||
const all = [...groups];
|
||||
// a page of folders, or as many as were drawn before, and down to the
|
||||
// folder of the session opened to its details
|
||||
const at = detail ? all.findIndex(([, items]) => items.some((s) => s.id === detail)) : -1;
|
||||
const n = Math.min(all.length, Math.max(drawnIn.get(FOLDERS) || SM_PAGE, at + 1));
|
||||
for (const [cwd, items] of all.slice(0, n)) tree.append(folder(cwd, items, q));
|
||||
if (n < all.length) tree.append(moreFolders(all, n, q));
|
||||
toFocus();
|
||||
}
|
||||
|
||||
// moreFolders adds the next page of folders above itself, as moreRow does
|
||||
// a folder's sessions
|
||||
function moreFolders(all, n, q) {
|
||||
drawnIn.set(FOLDERS, n);
|
||||
const b = el("button", "text sess-page-more sm-more-folders");
|
||||
b.type = "button";
|
||||
b.dataset.unrolls = ""; // it goes down with the folders it opens
|
||||
const label = () => t("Show {n} more folders", { n: Math.min(SM_PAGE, all.length - n) });
|
||||
b.textContent = label();
|
||||
b.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
const next = Math.min(all.length, n + SM_PAGE);
|
||||
b.before(...all.slice(n, next).map(([cwd, items]) => folder(cwd, items, q)));
|
||||
n = next;
|
||||
drawnIn.set(FOLDERS, n);
|
||||
if (n >= all.length) b.remove();
|
||||
else b.textContent = label();
|
||||
};
|
||||
return b;
|
||||
}
|
||||
|
||||
function folder(cwd, items, q) {
|
||||
const open = !!q || opened.has(cwd);
|
||||
const g = el("div", "list sm-group");
|
||||
const r = el("div", "row sm-folder");
|
||||
const writable = items.filter((s) => s.deletable);
|
||||
// the folder's box picks every session of it shown, folded or not,
|
||||
// for the bar's Delete; the bar still counts sessions (#527)
|
||||
if (current()?.deletable && writable.length) {
|
||||
const c = el("input", "sm-check sm-folder-check");
|
||||
c.type = "checkbox";
|
||||
// a session's own box ticked or not shows here at once
|
||||
c.sync = () => {
|
||||
c.checked = writable.every((s) => picked.has(s.id));
|
||||
c.indeterminate = !c.checked && writable.some((s) => picked.has(s.id));
|
||||
};
|
||||
c.sync();
|
||||
folderBoxes.set(cwd, c);
|
||||
c.setAttribute("aria-label", t("Select every session in {folder}", { folder: groupName(cwd) }));
|
||||
c.onclick = (e) => e.stopPropagation();
|
||||
c.onchange = () => {
|
||||
for (const s of writable) c.checked ? picked.add(s.id) : picked.delete(s.id);
|
||||
redrawList();
|
||||
};
|
||||
const path = cwd === GW ? "" : cwd;
|
||||
r.append(fold, el("span", "sub sm-path", path), el("span", "grow"), el("span", "note", t(items.length === 1 ? "{n} session" : "{n} sessions", { n: items.length })));
|
||||
|
||||
r.title = path;
|
||||
g.append(r);
|
||||
if (open) {
|
||||
// a page, or as many as were drawn before, and down to the session
|
||||
// opened to its details (from the Usage page's list, #752)
|
||||
const at = detail ? items.findIndex((s) => s.id === detail) : -1;
|
||||
const n = Math.min(items.length, Math.max(drawnIn.get(cwd) || SM_PAGE, at + 1));
|
||||
for (const s of items.slice(0, n)) g.append(item(s));
|
||||
if (n < items.length) g.append(moreRow(cwd, items, n));
|
||||
}
|
||||
tree.append(g);
|
||||
r.append(c);
|
||||
}
|
||||
toFocus();
|
||||
const fold = el("button", "fold");
|
||||
fold.type = "button";
|
||||
fold.setAttribute("aria-expanded", String(open));
|
||||
fold.append(svg(CHEV_R, 10, 1.6), el("span", "name", groupName(cwd)));
|
||||
fold.onclick = () => {
|
||||
if (opened.has(cwd)) opened.delete(cwd); else opened.add(cwd);
|
||||
redrawList();
|
||||
};
|
||||
const path = cwd === GW ? "" : cwd;
|
||||
r.append(fold, el("span", "sub sm-path", path), el("span", "grow"), el("span", "note", t(items.length === 1 ? "{n} session" : "{n} sessions", { n: items.length })));
|
||||
|
||||
r.title = path;
|
||||
g.append(r);
|
||||
if (open) {
|
||||
// a page, or as many as were drawn before, and down to the session
|
||||
// opened to its details (from the Usage page's list, #752)
|
||||
const at = detail ? items.findIndex((s) => s.id === detail) : -1;
|
||||
const n = Math.min(items.length, Math.max(drawnIn.get(cwd) || SM_PAGE, at + 1));
|
||||
for (const s of items.slice(0, n)) g.append(item(s));
|
||||
if (n < items.length) g.append(moreRow(cwd, items, n));
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
// moreRow adds the folder's next page of sessions above itself, leaving
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The Sessions page of an agent whose sessions each ran in a folder of their
|
||||
// own (an app that runs Codex once per picture left 11,358 folders of one
|
||||
// session each, and drawing every folder made 114,000 elements: every click
|
||||
// to the page held it for over a second, and the Library page after it).
|
||||
// The folders are drawn 100 at a time with a "Show N more folders" that adds
|
||||
// the next page under them, leaving what is drawn, and where the reader is,
|
||||
// as it was; a filter and another agent start again at a page, unfolding a
|
||||
// folder keeps the folders drawn, and a session opened from the Usage page
|
||||
// is drawn however far down the folders it is. Every language, Chromium and
|
||||
// WebKit, wide and narrow.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const N = 250; // two pages of folders and a half
|
||||
const at = (min) => new Date(Date.now() - min * 60e3).toISOString();
|
||||
const sessions = (agent) => Array.from({ length: agent === "codex" ? N : 3 }, (_, i) => ({
|
||||
agent, id: `${agent}-${i}`, cwd: `/pictures/inputs/${String(i).padStart(4, "0")}`, title: `${agent} picture ${i}`,
|
||||
start: at(i + 5), last: at(i + 1), input: 1000, output: 100, cost: 0.1, priced: true,
|
||||
models: [{ model: "gpt-5.5", input: 1000, output: 100, cost: 0.1, priced: true }],
|
||||
messages: 6, files: 1, size: 4096, deletable: true, resume: `${agent} resume ${agent}-${i}`,
|
||||
}));
|
||||
const agents = [{ agent: "codex", name: "Codex", icon: "openai", count: N, deletable: true }, { agent: "claude", name: "Claude Code", icon: "claudecode-color", count: 3, deletable: true }];
|
||||
const words = {
|
||||
en: { more: "Show 100 more folders", rest: "Show 50 more folders", all: `${N} selected` },
|
||||
zh: { more: "显示其余 100 个文件夹", rest: "显示其余 50 个文件夹", all: `已选 ${N} 个` },
|
||||
"zh-TW": { more: "顯示其餘 100 個資料夾", rest: "顯示其餘 50 個資料夾" },
|
||||
ja: { more: "さらに 100 個のフォルダを表示", rest: "さらに 50 個のフォルダを表示" },
|
||||
de: { more: "100 weitere Ordner anzeigen", rest: "50 weitere Ordner anzeigen" },
|
||||
};
|
||||
|
||||
function serve(lang) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/sessions/manage") {
|
||||
const agent = url.searchParams.get("agent") === "claude" ? "claude" : "codex";
|
||||
return json({ agents, agent, sessions: sessions(agent), trash: [] });
|
||||
}
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
const body = await fs.readFile(file).catch(() => null);
|
||||
return body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
test(`${engine} ${lang}: thousands of folders are drawn a page at a time`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const w = words[lang];
|
||||
for (const width of [1000, 380]) {
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 640 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message + " " + e.stack));
|
||||
await page.route("**/*", serve(lang));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('#nav [data-view="sessions"]').click();
|
||||
const view = page.locator("#view-sessions");
|
||||
const folders = view.locator(".row.sm-folder");
|
||||
const more = view.locator(".sm-more-folders");
|
||||
await folders.first().waitFor();
|
||||
assert.equal(await folders.count(), 100, "one page of folders is drawn");
|
||||
assert.equal(await more.textContent(), w.more);
|
||||
const box = await more.boundingBox();
|
||||
assert(box.x >= 0 && box.x + box.width <= width, `${width}px: Show more folders fits`);
|
||||
|
||||
// the next page goes under the folders drawn; they and the scroll stay
|
||||
await page.mouse.move(width / 2, 320);
|
||||
const inSight = () => folders.nth(99).evaluate((e) => { const r = e.getBoundingClientRect(); return r.top >= 0 && r.bottom <= innerHeight; });
|
||||
for (let i = 0; i < 300 && !(await inSight()); i++) await page.mouse.wheel(0, 200);
|
||||
await page.waitForTimeout(300);
|
||||
assert(await inSight(), "the reader's wheel brings the last folder drawn into sight");
|
||||
await folders.first().evaluate((e) => { e.kept = true; });
|
||||
const y = () => folders.nth(99).evaluate((e) => Math.round(e.getBoundingClientRect().top));
|
||||
const before = await y();
|
||||
await more.evaluate((e) => e.click());
|
||||
assert.equal(await folders.count(), 200);
|
||||
assert.equal(await y(), before, "Show more folders doesn't move the folders in sight");
|
||||
assert(await folders.first().evaluate((e) => e.kept === true), "the folders drawn are kept, not drawn again");
|
||||
assert.equal(await more.textContent(), w.rest);
|
||||
|
||||
// unfolding a folder keeps as many folders drawn
|
||||
await folders.nth(150).locator(".fold").evaluate((e) => e.click());
|
||||
await view.locator('.row.sm-sess[data-id="codex-150"]').waitFor();
|
||||
assert.equal(await folders.count(), 200, "unfolding a folder keeps the folders drawn");
|
||||
await more.evaluate((e) => e.click());
|
||||
assert.equal(await folders.count(), N);
|
||||
assert.equal(await more.count(), 0, "the last page leaves no Show more folders");
|
||||
|
||||
// the bar picks every session, its folder drawn or not
|
||||
if (w.all) {
|
||||
await page.locator('#nav [data-view="agents"]').click();
|
||||
await page.locator('#nav [data-view="sessions"]').click();
|
||||
assert.equal(await folders.count(), N, "coming back to the page keeps the folders drawn");
|
||||
// back to the top as the reader goes there: a scroll of code's own
|
||||
// is put back (WebKit)
|
||||
await page.mouse.move(width / 2, 320);
|
||||
await page.mouse.wheel(0, -40000);
|
||||
await page.waitForFunction(() => document.querySelector("#view-sessions").scrollTop === 0);
|
||||
await view.locator(".sm-bar .sm-check").check();
|
||||
assert.equal(await view.locator(".sm-bar .sm-count").textContent(), w.all);
|
||||
await view.locator(".sm-bar .sm-check").uncheck();
|
||||
}
|
||||
|
||||
// a filter starts again at a page; one that finds a few draws those
|
||||
const filter = view.locator(".sm-filter");
|
||||
await filter.fill("picture");
|
||||
assert.equal(await folders.count(), 100, "a filter starts again at a page of folders");
|
||||
await filter.fill("picture 249");
|
||||
assert.equal(await folders.count(), 1);
|
||||
assert.equal(await more.count(), 0);
|
||||
await filter.fill("");
|
||||
assert.equal(await folders.count(), 100);
|
||||
|
||||
// another agent starts at a page; a session opened from the Usage
|
||||
// page, far down the folders, is drawn
|
||||
await page.evaluate(() => window.openSessionOnPage({ agent: "claude" }));
|
||||
await view.locator('.row.sm-sess[data-id^="claude"]').first().waitFor();
|
||||
assert.equal(await folders.count(), 3);
|
||||
await page.evaluate(() => window.openSessionOnPage({ agent: "codex", id: "codex-230", cwd: "/pictures/inputs/0230" }));
|
||||
await view.locator('.sm-item.open .row.sm-sess[data-id="codex-230"]').waitFor();
|
||||
assert.equal(await folders.count(), 231, "drawn down to the folder of the session opened");
|
||||
assert(await view.locator(".row.sm-sess").count() <= 1, "only that folder is unfolded");
|
||||
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-sessions-folder-paging.png`) });
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
await page.context().close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user