@devries-cameron20 / t3code Mirror · read-only / commits / 442d5ca655
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(web): stored pull request details keep only the 20 most recent (#21245)

tiliakoos committed Oct 18, 2026 at 15:34 UTC 442d5ca6555e622f3441bd53bf7fa38ed23af152
2 files changed +54 -5
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+28
@@ -1825,9 +1825,37 @@ describe("cached pull request detail", () => {
1825 return {
1826 getItem: (key: string) => held.get(key) ?? null,
1827 setItem: (key: string, value: string) => void held.set(key, value),
1828 + removeItem: (key: string) => void held.delete(key),
1829 + size: () => held.size,
1830 };
1831 };
1832
1833 + it("keeps only the 20 most recently saved pull requests", () => {
1834 + const storage = makeStorage();
1835 + const numbered = (number: number) => ({ ...reference, number });
1836 + for (let number = 1; number <= 21; number += 1) {
1837 + writePullRequestDetailSnapshot(storage, "env-1", numbered(number), detail({ number }));
1838 + }
1839 + expect(readPullRequestDetailSnapshot(storage, "env-1", numbered(1))).toBeNull();
1840 + expect(readPullRequestDetailSnapshot(storage, "env-1", numbered(2))?.number).toBe(2);
1841 + expect(readPullRequestDetailSnapshot(storage, "env-1", numbered(21))?.number).toBe(21);
1842 + // Twenty snapshots plus the list of their keys.
1843 + expect(storage.size()).toBe(21);
1844 + });
1845 +
1846 + it("saving a pull request again keeps it as the newest without growing the list", () => {
1847 + const storage = makeStorage();
1848 + const numbered = (number: number) => ({ ...reference, number });
1849 + for (let number = 1; number <= 20; number += 1) {
1850 + writePullRequestDetailSnapshot(storage, "env-1", numbered(number), detail({ number }));
1851 + }
1852 + writePullRequestDetailSnapshot(storage, "env-1", numbered(1), detail({ number: 1 }));
1853 + writePullRequestDetailSnapshot(storage, "env-1", numbered(21), detail({ number: 21 }));
1854 + expect(readPullRequestDetailSnapshot(storage, "env-1", numbered(1))?.number).toBe(1);
1855 + expect(readPullRequestDetailSnapshot(storage, "env-1", numbered(2))).toBeNull();
1856 + expect(storage.size()).toBe(21);
1857 + });
1858 +
1859 it("hydrates the last title, author, and counts so a reopen does not ghost the tab", () => {
1860 const storage = makeStorage();
1861 writePullRequestDetailSnapshot(storage, "env-1", reference, detail());
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+26 -5
@@ -1152,7 +1152,7 @@ export function canDeletePullRequestBranch(
1152 );
1153 }
1154
1155 -type SnapshotStorage = Pick<Storage, "getItem" | "setItem">;
1155 +type SnapshotStorage = Pick<Storage, "getItem" | "setItem" | "removeItem">;
1156
1157 export function resolvePullRequestReferenceHost(
1158 reference: PullRequestRef,
@@ -1203,17 +1203,38 @@ export function readPullRequestDetailSnapshot(
1203 }
1204 }
1205
1206 +// Snapshot keys in the order they were last written, oldest first.
1207 +const PULL_REQUEST_DETAIL_SNAPSHOT_INDEX_KEY = "t3.pullRequests.recentDetails";
1208 +const PULL_REQUEST_DETAIL_SNAPSHOT_LIMIT = 20;
1209 +
1210 +function readPullRequestDetailSnapshotIndex(storage: SnapshotStorage): string[] {
1211 + try {
1212 + const keys: unknown = JSON.parse(
1213 + storage.getItem(PULL_REQUEST_DETAIL_SNAPSHOT_INDEX_KEY) ?? "[]",
1214 + );
1215 + return Array.isArray(keys) ? keys.filter((key): key is string => typeof key === "string") : [];
1216 + } catch {
1217 + return [];
1218 + }
1219 +}
1220 +
1221 +// Keeps the snapshots of the 20 most recently saved pull requests and removes older ones.
1222 export function writePullRequestDetailSnapshot(
1223 storage: SnapshotStorage | undefined,
1224 environmentId: string,
1225 reference: PullRequestDetailSnapshotRef,
1226 detail: PullRequestDetail,
1227 ): void {
1228 + if (!storage) return;
1229 try {
1213 - storage?.setItem(
1214 - pullRequestDetailSnapshotKey(environmentId, reference),
1215 - JSON.stringify(detail),
1216 - );
1230 + const key = pullRequestDetailSnapshotKey(environmentId, reference);
1231 + const recent = readPullRequestDetailSnapshotIndex(storage).filter((entry) => entry !== key);
1232 + recent.push(key);
1233 + for (const evicted of recent.splice(0, recent.length - PULL_REQUEST_DETAIL_SNAPSHOT_LIMIT)) {
1234 + storage.removeItem(evicted);
1235 + }
1236 + storage.setItem(PULL_REQUEST_DETAIL_SNAPSHOT_INDEX_KEY, JSON.stringify(recent));
1237 + storage.setItem(key, JSON.stringify(detail));
1238 } catch {}
1239 }
1240