From 3980cb0cd5352e4357b69a124e0a9a1e0cc75b16 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:18:32 +0000 Subject: [PATCH 1/5] Add batched commit summaries for commit lists --- native/gitinspection/changes.go | 97 ++++++++++++++++++++++++++-- native/gitinspection/fractch_test.go | 18 ++++++ native/gitinspection/inspection.go | 2 + opal.json | 2 +- scripts/e2e_smoke.py | 3 + src/git/git-inspection.osl | 61 +++++++++++++++++ src/git/routes.osl | 1 + 7 files changed, 177 insertions(+), 7 deletions(-) diff --git a/native/gitinspection/changes.go b/native/gitinspection/changes.go index 80d3d2a..ef7c4ca 100644 --- a/native/gitinspection/changes.go +++ b/native/gitinspection/changes.go @@ -216,14 +216,21 @@ func treeFiles(source archive, tree string) (map[string]gitFile, bool) { return files, true } -func changesBetween(baseArchive archive, baseSHA string, baseCommit gitCommit, headArchive archive, headSHA string, headCommit gitCommit) string { +type commitChanges struct { + legacy bool + targets []fractchTargetChanges + others []map[string]any + totals changeTotals +} + +func computeChanges(baseArchive archive, baseCommit gitCommit, headArchive archive, headCommit gitCommit, inline bool) (commitChanges, string) { parentFiles, ok := treeFiles(baseArchive, baseCommit.Tree) if !ok { - return failure("parent commit tree is invalid") + return commitChanges{}, "parent commit tree is invalid" } currentFiles, ok := treeFiles(headArchive, headCommit.Tree) if !ok || headCommit.Tree == "" { - return failure("commit tree is invalid") + return commitChanges{}, "commit tree is invalid" } changes := []map[string]any{} legacy := false @@ -247,13 +254,91 @@ func changesBetween(baseArchive archive, baseSHA string, baseCommit gitCommit, h } sortChanges(changes) targets, others, totals := structuredChanges(changes, baseArchive, parentFiles, headArchive, currentFiles) - inlineDiffContent(others, baseArchive, parentFiles, headArchive, currentFiles) + if inline { + inlineDiffContent(others, baseArchive, parentFiles, headArchive, currentFiles) + } + return commitChanges{legacy: legacy, targets: targets, others: others, totals: totals}, "" +} + +func changesBetween(baseArchive archive, baseSHA string, baseCommit gitCommit, headArchive archive, headSHA string, headCommit gitCommit) string { + computed, problem := computeChanges(baseArchive, baseCommit, headArchive, headCommit, true) + if problem != "" { + return failure(problem) + } return encode(map[string]any{ - "ok": true, "sha": headSHA, "parent": baseSHA, "commit": headCommit, "legacy": legacy, - "targets": targets, "files": others, "totals": totals, + "ok": true, "sha": headSHA, "parent": baseSHA, "commit": headCommit, "legacy": computed.legacy, + "targets": computed.targets, "files": computed.others, "totals": computed.totals, }, "could not encode commit changes") } +const maxSummarySprites = 5 + +func summarizeComputed(computed commitChanges) map[string]any { + assetDirs := map[string]bool{} + for _, file := range computed.others { + path, _ := file["path"].(string) + if isAssetPath(path) { + assetDirs[spriteDir(path)] = true + } + } + sprites := []string{} + count := 0 + for _, target := range computed.targets { + if len(target.Scripts) == 0 && len(target.Items) == 0 && !target.TooLarge && !assetDirs[target.Path] { + continue + } + delete(assetDirs, target.Path) + count++ + if len(sprites) < maxSummarySprites { + sprites = append(sprites, summaryName(target.Path, target.Name)) + } + } + remaining := make([]string, 0, len(assetDirs)) + for dir := range assetDirs { + remaining = append(remaining, dir) + } + sort.Strings(remaining) + for _, dir := range remaining { + count++ + if len(sprites) < maxSummarySprites { + sprites = append(sprites, summaryName(dir, "")) + } + } + return map[string]any{"legacy": computed.legacy, "totals": computed.totals, "sprites": sprites, "spriteCount": count} +} + +func summaryName(dir, name string) string { + if dir == "Stage" { + return "Stage" + } + if name != "" { + return name + } + return dir +} + +func (a archive) inspectCommitSummary(sha string, commit gitCommit) string { + base := archive{objects: map[string]*zip.File{}} + parentCommit := gitCommit{} + initial := len(commit.Parents) == 0 + if !initial { + parsed, ok := a.parseCommit(commit.Parents[0]) + if !ok { + return failure("parent commit is unavailable") + } + base, parentCommit = a, parsed + } + computed, problem := computeChanges(base, parentCommit, a, commit, false) + if problem != "" { + return failure(problem) + } + summary := summarizeComputed(computed) + summary["ok"] = true + summary["sha"] = sha + summary["initial"] = initial + return encode(summary, "could not encode commit summary") +} + func (a archive) inspectCommitChanges(sha string, commit gitCommit) string { if len(commit.Parents) == 0 { return changesBetween(archive{objects: map[string]*zip.File{}}, "", gitCommit{}, a, sha, commit) diff --git a/native/gitinspection/fractch_test.go b/native/gitinspection/fractch_test.go index 33f2feb..4a50af3 100644 --- a/native/gitinspection/fractch_test.go +++ b/native/gitinspection/fractch_test.go @@ -298,6 +298,24 @@ func TestInspectChangesSummarisesCommit(t *testing.T) { } } + summary := decodeResult(t, Inspect(path, second, "summary", "", second)) + if summary["ok"] != true || summary["initial"] != false || summary["spriteCount"] != float64(2) { + t.Fatalf("unexpected summary: %v", summary) + } + if names := summary["sprites"].([]any); len(names) != 2 || names[0] != "Cat" || names[1] != "Stage" { + t.Fatalf("unexpected summary sprites: %v", names) + } + if summary["totals"].(map[string]any)["scripts"].(map[string]any)["changed"] != float64(1) { + t.Fatalf("summary totals differ from the changes view: %v", summary["totals"]) + } + if _, inlined := summary["files"]; inlined { + t.Fatalf("a summary should not carry file contents: %v", summary) + } + firstSummary := decodeResult(t, Inspect(path, first, "summary", "", second)) + if firstSummary["initial"] != true { + t.Fatalf("the first commit should be marked initial: %v", firstSummary) + } + initial := decodeResult(t, Inspect(path, first, "changes", "", second)) initialTotals := initial["totals"].(map[string]any) if initialTotals["scripts"].(map[string]any)["added"] != float64(3) || initialTotals["stateOnly"] != false { diff --git a/native/gitinspection/inspection.go b/native/gitinspection/inspection.go index e4e08d4..649765b 100644 --- a/native/gitinspection/inspection.go +++ b/native/gitinspection/inspection.go @@ -349,6 +349,8 @@ func Inspect(workspacePath, sha, operation, requestedPath, allowedHeads string) return archive.inspectCommit(sha, commit, true) case "changes": return archive.inspectCommitChanges(sha, commit) + case "summary": + return archive.inspectCommitSummary(sha, commit) default: return archive.inspectCommit(sha, commit, false) } diff --git a/opal.json b/opal.json index a1a0de4..7da1afe 100644 --- a/opal.json +++ b/opal.json @@ -1,6 +1,6 @@ { "name": "mistwarp-api", - "version": "1.2.0", + "version": "1.3.0", "main": "main.osl", "scripts": { "dev": ["osl", "run", "main.osl"], diff --git a/scripts/e2e_smoke.py b/scripts/e2e_smoke.py index b8ddfaa..f110cfe 100644 --- a/scripts/e2e_smoke.py +++ b/scripts/e2e_smoke.py @@ -644,6 +644,9 @@ def head_and_edited(): step("commit changes", "GET", path + "/commits/" + head + "/changes", "sam") step("commit changes signed out", "GET", path + "/commits/" + head + "/changes") step("changes of unknown commit", "GET", path + "/commits/" + "1" * 40 + "/changes", "sam") + step("commit summaries", "GET", path + "/commit-summaries?shas=" + head + ",nothex," + "1" * 40 + "," + head, "sam") + step("commit summaries signed out", "GET", path + "/commit-summaries?shas=" + head) + step("commit summaries without shas", "GET", path + "/commit-summaries", "sam") step("rename branch", "PATCH", path + "/branches", "sam", {"branch": "feature", "name": "feature-two"}) step("rename branch as stranger", "PATCH", path + "/branches", "bob", {"branch": "feature-two", "name": "x"}) step("delete branch", "DELETE", path + "/branches", "sam", {"branch": "feature-two"}) diff --git a/src/git/git-inspection.osl b/src/git/git-inspection.osl index b1274a4..4667dd8 100644 --- a/src/git/git-inspection.osl +++ b/src/git/git-inspection.osl @@ -285,3 +285,64 @@ def handleGetCommitFile(*serve.Context c) ( ) gitInspectionResponse(c, res.project.assert(object), c.param("sha"), "file", (c.query("path") ?? "")) ) + +def commitSummaryLimit() number ( + return 50 +) + +def requestedCommitShas(string raw) array ( + array shas = [] + object seen = {} + for entry in raw.split(",") ( + string sha = entry.toStr().trim() + if validGitObjectId(sha) and !seen.contains(sha) and shas.len < commitSummaryLimit() ( + seen[sha] = true + shas.append(sha) + ) + ) + return shas +) + +def handleGetCommitSummaries(*serve.Context c) ( + c.setHeader("Cache-Control", "private, no-store") + c.setHeader("CDN-Cache-Control", "private, no-store") + auto res = loadProject(c.param("id")) + if !res.ok ( + c.notFound("project not found") + return + ) + object project = res.project.assert(object) + if !canSeeInsideProject(project, c) ( + c.notFound("project not found") + return + ) + array shas = requestedCommitShas((c.query("shas") ?? "")) + object summaries = {} + if shas.len == 0 ( + c.json(200, {ok: true, summaries: summaries}) + return + ) + string allowedHeads = projectGitAllowedHeadsString(project) + if allowedHeads == "" ( + c.json(200, {ok: true, summaries: summaries}) + return + ) + string workspacePath = cachedProjectWorkspacePath(project) + if workspacePath == "" ( + c.notFound("workspace not found") + return + ) + for i shas.len ( + string sha = shas[i].toStr() + if projectRecordsCommit(project, sha) ( + auto parsed = json.parse(cachedWorkspaceGitInspectionJSON(project, workspacePath, sha, "summary", "", allowedHeads), {type: "object"}) + if !parsed.isErr() ( + object summary = parsed.unwrap().assert(object) + if summary.contains("ok") and summary.ok == true ( + summaries[sha] = summary + ) + ) + ) + ) + c.json(200, {ok: true, summaries: summaries}) +) diff --git a/src/git/routes.osl b/src/git/routes.osl index 5f727c6..06c4d40 100644 --- a/src/git/routes.osl +++ b/src/git/routes.osl @@ -5,6 +5,7 @@ export { def registerGitRoutes(*serve.Router api) ( api.GET("/projects/:id/commits", handleGetCommits) + api.GET("/projects/:id/commit-summaries", handleGetCommitSummaries) api.GET("/projects/:id/branches", handleListProjectBranches) api.POST("/projects/:id/branches", requireAuth, handleCreateProjectBranch) api.PATCH("/projects/:id/branches", requireAuth, handleRenameProjectBranch) From 9a6829f255bdbb3c4db17363781d824bca98816f Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:22:08 +0000 Subject: [PATCH 2/5] Count authored files and oversized sprites in commit summaries --- native/gitinspection/changes.go | 10 +++++++++- native/gitinspection/fractch_test.go | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/native/gitinspection/changes.go b/native/gitinspection/changes.go index ef7c4ca..0a444c9 100644 --- a/native/gitinspection/changes.go +++ b/native/gitinspection/changes.go @@ -275,15 +275,20 @@ const maxSummarySprites = 5 func summarizeComputed(computed commitChanges) map[string]any { assetDirs := map[string]bool{} + files := 0 for _, file := range computed.others { path, _ := file["path"].(string) if isAssetPath(path) { assetDirs[spriteDir(path)] = true + } else if path != "fractch.json" { + files++ } } sprites := []string{} count := 0 + tooLarge := false for _, target := range computed.targets { + tooLarge = tooLarge || target.TooLarge if len(target.Scripts) == 0 && len(target.Items) == 0 && !target.TooLarge && !assetDirs[target.Path] { continue } @@ -304,7 +309,10 @@ func summarizeComputed(computed commitChanges) map[string]any { sprites = append(sprites, summaryName(dir, "")) } } - return map[string]any{"legacy": computed.legacy, "totals": computed.totals, "sprites": sprites, "spriteCount": count} + return map[string]any{ + "legacy": computed.legacy, "totals": computed.totals, "sprites": sprites, "spriteCount": count, + "authoredFiles": files, "tooLarge": tooLarge, + } } func summaryName(dir, name string) string { diff --git a/native/gitinspection/fractch_test.go b/native/gitinspection/fractch_test.go index 4a50af3..15382c0 100644 --- a/native/gitinspection/fractch_test.go +++ b/native/gitinspection/fractch_test.go @@ -308,6 +308,9 @@ func TestInspectChangesSummarisesCommit(t *testing.T) { if summary["totals"].(map[string]any)["scripts"].(map[string]any)["changed"] != float64(1) { t.Fatalf("summary totals differ from the changes view: %v", summary["totals"]) } + if summary["authoredFiles"] != float64(1) || summary["tooLarge"] != false { + t.Fatalf("summary should count the readme and nothing else: %v", summary) + } if _, inlined := summary["files"]; inlined { t.Fatalf("a summary should not carry file contents: %v", summary) } From 65e12b2a6d989e743d8f5aff2fa659a60887021b Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:35:16 +0000 Subject: [PATCH 3/5] Keep commit summaries in one cache file per project --- scripts/e2e_smoke.py | 1 + src/git/git-inspection.osl | 77 +++++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/scripts/e2e_smoke.py b/scripts/e2e_smoke.py index f110cfe..2c100b9 100644 --- a/scripts/e2e_smoke.py +++ b/scripts/e2e_smoke.py @@ -646,6 +646,7 @@ def head_and_edited(): step("changes of unknown commit", "GET", path + "/commits/" + "1" * 40 + "/changes", "sam") step("commit summaries", "GET", path + "/commit-summaries?shas=" + head + ",nothex," + "1" * 40 + "," + head, "sam") step("commit summaries signed out", "GET", path + "/commit-summaries?shas=" + head) + step("commit summaries from cache", "GET", path + "/commit-summaries?shas=" + head, "sam") step("commit summaries without shas", "GET", path + "/commit-summaries", "sam") step("rename branch", "PATCH", path + "/branches", "sam", {"branch": "feature", "name": "feature-two"}) step("rename branch as stranger", "PATCH", path + "/branches", "bob", {"branch": "feature-two", "name": "x"}) diff --git a/src/git/git-inspection.osl b/src/git/git-inspection.osl index 4667dd8..3f54185 100644 --- a/src/git/git-inspection.osl +++ b/src/git/git-inspection.osl @@ -303,6 +303,46 @@ def requestedCommitShas(string raw) array ( return shas ) +def commitSummaryCacheDir() string ( + return tmpDir ++ "git-summaries/" +) + +def commitSummaryCacheName(object project) string ( + return gitInspectionCacheVersion() ++ "." ++ project.id.toStr().hashSHA256() ++ ".json" +) + +def readCommitSummaryCache(string cachePath) object ( + if !fs.exists(cachePath) or fs.size(cachePath).unwrapOr(0) > 8388608 ( + return {} + ) + auto parsed = json.parse(fs.readFile(cachePath).unwrapOr(""), {type: "object"}) + if parsed.isErr() ( + return {} + ) + return parsed.unwrap().assert(object) +) + +def computeCommitSummary(string workspacePath, string sha, string allowedHeads) object ( + auto parsed = json.parse(gitinspection.Inspect(workspacePath, sha, "summary", "", allowedHeads), {type: "object"}) + if parsed.isErr() ( + return {} + ) + object summary = parsed.unwrap().assert(object) + if !summary.contains("ok") or summary.ok != true ( + return {} + ) + return summary +) + +def writeCommitSummaryCache(string cachePath, object cached) ( + string temporaryPath = cachePath ++ ".tmp." ++ randomString(8) + if fs.writeFile(temporaryPath, json.stringify(cached)) ( + if !fs.rename(temporaryPath, cachePath) ( + void fs.remove(temporaryPath) + ) + ) +) + def handleGetCommitSummaries(*serve.Context c) ( c.setHeader("Cache-Control", "private, no-store") c.setHeader("CDN-Cache-Control", "private, no-store") @@ -327,22 +367,41 @@ def handleGetCommitSummaries(*serve.Context c) ( c.json(200, {ok: true, summaries: summaries}) return ) - string workspacePath = cachedProjectWorkspacePath(project) - if workspacePath == "" ( - c.notFound("workspace not found") - return - ) + string cacheDir = commitSummaryCacheDir() + void fs.mkdir(cacheDir, {recursive: true}) + string cacheName = commitSummaryCacheName(project) + string cachePath = cacheDir ++ cacheName + string lockName = "git-summaries-" ++ cacheName + sync.lock(lockName) + defer sync.unlock(lockName) + object cached = readCommitSummaryCache(cachePath) + boolean changed = false + string workspacePath = "" for i shas.len ( string sha = shas[i].toStr() if projectRecordsCommit(project, sha) ( - auto parsed = json.parse(cachedWorkspaceGitInspectionJSON(project, workspacePath, sha, "summary", "", allowedHeads), {type: "object"}) - if !parsed.isErr() ( - object summary = parsed.unwrap().assert(object) - if summary.contains("ok") and summary.ok == true ( + if cached.contains(sha) and cached[sha] != null ( + summaries[sha] = cached[sha] + ) else ( + if workspacePath == "" ( + workspacePath = cachedProjectWorkspacePath(project) + if workspacePath == "" ( + c.notFound("workspace not found") + return + ) + ) + object summary = computeCommitSummary(workspacePath, sha, allowedHeads) + if summary.contains("ok") ( summaries[sha] = summary + cached[sha] = summary + changed = true ) ) ) ) + if changed ( + writeCommitSummaryCache(cachePath, cached) + pruneGitInspectionCache(cacheDir, cacheName) + ) c.json(200, {ok: true, summaries: summaries}) ) From 9757fef0bc6f9f65f11e67203f5efa1b759c6979 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:44:54 +0000 Subject: [PATCH 4/5] Compute summaries outside the cache lock and skip non-sprite folders --- native/gitinspection/changes.go | 25 +++++++-- native/gitinspection/fractch_test.go | 55 ++++++++++++++++++ scripts/e2e_smoke.py | 4 ++ src/git/commit-summary-cache.osl | 51 +++++++++++++++++ src/git/commit-summary-cache.test.osl | 34 ++++++++++++ src/git/git-inspection.osl | 80 +++++++++++---------------- 6 files changed, 196 insertions(+), 53 deletions(-) create mode 100644 src/git/commit-summary-cache.osl create mode 100644 src/git/commit-summary-cache.test.osl diff --git a/native/gitinspection/changes.go b/native/gitinspection/changes.go index 0a444c9..81eeed7 100644 --- a/native/gitinspection/changes.go +++ b/native/gitinspection/changes.go @@ -217,10 +217,21 @@ func treeFiles(source archive, tree string) (map[string]gitFile, bool) { } type commitChanges struct { - legacy bool - targets []fractchTargetChanges - others []map[string]any - totals changeTotals + legacy bool + targets []fractchTargetChanges + others []map[string]any + totals changeTotals + spriteDirs map[string]bool +} + +func spriteDirsOf(trees ...map[string]gitFile) map[string]bool { + dirs := map[string]bool{} + for _, files := range trees { + for dir := range fractchFilesByDir(files) { + dirs[dir] = true + } + } + return dirs } func computeChanges(baseArchive archive, baseCommit gitCommit, headArchive archive, headCommit gitCommit, inline bool) (commitChanges, string) { @@ -257,7 +268,7 @@ func computeChanges(baseArchive archive, baseCommit gitCommit, headArchive archi if inline { inlineDiffContent(others, baseArchive, parentFiles, headArchive, currentFiles) } - return commitChanges{legacy: legacy, targets: targets, others: others, totals: totals}, "" + return commitChanges{legacy: legacy, targets: targets, others: others, totals: totals, spriteDirs: spriteDirsOf(parentFiles, currentFiles)}, "" } func changesBetween(baseArchive archive, baseSHA string, baseCommit gitCommit, headArchive archive, headSHA string, headCommit gitCommit) string { @@ -279,7 +290,9 @@ func summarizeComputed(computed commitChanges) map[string]any { for _, file := range computed.others { path, _ := file["path"].(string) if isAssetPath(path) { - assetDirs[spriteDir(path)] = true + if dir := spriteDir(path); dir != "" && computed.spriteDirs[dir] { + assetDirs[dir] = true + } } else if path != "fractch.json" { files++ } diff --git a/native/gitinspection/fractch_test.go b/native/gitinspection/fractch_test.go index 15382c0..b268ad4 100644 --- a/native/gitinspection/fractch_test.go +++ b/native/gitinspection/fractch_test.go @@ -2,6 +2,7 @@ package gitinspection import ( "encoding/hex" + "encoding/json" "sort" "strings" "testing" @@ -340,6 +341,60 @@ func TestInspectChangesStateOnlyCommitIsNotCode(t *testing.T) { } } +func TestInspectSummaryNamesOnlySpriteFolders(t *testing.T) { + repo := newTestRepository() + code := repo.object("blob", []byte(fractchBase)) + firstTree := repo.nestedTree(map[string]string{ + "Cat/main.fractch": code, + "Cat/assets/a.svg": repo.object("blob", []byte("")), + "fonts/Brand.ttf": repo.object("blob", []byte("font one")), + "assets/loose.png": repo.object("blob", []byte("png one")), + "Stage/stage.fractch": repo.object("blob", []byte("stage \"Stage\";\n")), + }) + first := repo.commit(firstTree, "", "Initial version") + secondTree := repo.nestedTree(map[string]string{ + "Cat/main.fractch": code, + "Cat/assets/a.svg": repo.object("blob", []byte("")), + "fonts/Brand.ttf": repo.object("blob", []byte("font two")), + "assets/loose.png": repo.object("blob", []byte("png two")), + "Stage/stage.fractch": repo.object("blob", []byte("stage \"Stage\";\n")), + }) + second := repo.commit(secondTree, first, "Updated project") + path := repo.write(t) + summary := decodeResult(t, Inspect(path, second, "summary", "", second)) + if names := summary["sprites"].([]any); len(names) != 1 || names[0] != "Cat" || summary["spriteCount"] != float64(1) { + t.Fatalf("only the Cat folder should be named: %v", summary) + } + assets := summary["totals"].(map[string]any)["assets"].(map[string]any) + if assets["modified"] != float64(3) { + t.Fatalf("every changed asset should still be counted: %v", assets) + } + changes := decodeResult(t, Inspect(path, second, "changes", "", second)) + summaryTotals, _ := json.Marshal(summary["totals"]) + changeTotals, _ := json.Marshal(changes["totals"]) + if string(summaryTotals) != string(changeTotals) { + t.Fatalf("summary totals %s differ from changes totals %s", summaryTotals, changeTotals) + } +} + +func TestInspectSummaryStateOnlyAndMissingParent(t *testing.T) { + repo := newTestRepository() + firstTree := repo.nestedTree(map[string]string{"Cat/main.fractch": repo.object("blob", []byte(fractchBase))}) + first := repo.commit(firstTree, "", "Initial version") + moved := strings.Replace(fractchBase, `sprite "Cat" at 10,20`, `sprite "Cat" at 99,20`, 1) + second := repo.commit(repo.nestedTree(map[string]string{"Cat/main.fractch": repo.object("blob", []byte(moved))}), first, "Updated project") + orphan := repo.commit(firstTree, strings.Repeat("e", 40), "Updated project") + path := repo.write(t) + summary := decodeResult(t, Inspect(path, second, "summary", "", second+","+orphan)) + totals := summary["totals"].(map[string]any) + if totals["stateOnly"] != true || len(summary["sprites"].([]any)) != 0 || summary["spriteCount"] != float64(0) { + t.Fatalf("a state-only commit names no sprites: %v", summary) + } + if failed := decodeResult(t, Inspect(path, orphan, "summary", "", second+","+orphan)); failed["ok"] == true { + t.Fatalf("a commit whose parent is missing should fail: %v", failed) + } +} + func TestCompareArchivesChangesAcrossForks(t *testing.T) { base := newTestRepository() baseCommit := base.commit(base.nestedTree(map[string]string{"Cat/main.fractch": base.object("blob", []byte(fractchBase))}), "", "Initial version") diff --git a/scripts/e2e_smoke.py b/scripts/e2e_smoke.py index 2c100b9..c1de57e 100644 --- a/scripts/e2e_smoke.py +++ b/scripts/e2e_smoke.py @@ -591,6 +591,10 @@ def head_and_edited(): head, edited = head_and_edited() upload("upload live editor", {"expectedEdited": edited}, who="alice") + private_head, _ = head_and_edited() + step("commit summaries of a private project signed out", "GET", path + "/commit-summaries?shas=" + private_head) + step("commit summaries of a private project as a stranger", "GET", path + "/commit-summaries?shas=" + private_head, "bob") + step("commit summaries of a private project as an editor", "GET", path + "/commit-summaries?shas=" + private_head, "alice") step("share history", "POST", path + "/visibility", "sam", {"visibility": "public"}) status, remixed = step("remix history", "POST", path + "/remix", "alice", {}) remix_id = str(remixed.get("id", "") or (remixed.get("project") or {}).get("id", "")) if isinstance(remixed, dict) else "" diff --git a/src/git/commit-summary-cache.osl b/src/git/commit-summary-cache.osl new file mode 100644 index 0000000..a39af2f --- /dev/null +++ b/src/git/commit-summary-cache.osl @@ -0,0 +1,51 @@ +def commitSummaryLimit() number ( + return 50 +) + +def requestedCommitShas(string raw) array ( + array shas = [] + object seen = {} + for entry in raw.split(",") ( + string sha = entry.toStr().trim() + if regex.match("^[a-f0-9]{40}$", sha) and !seen.contains(sha) and shas.len < commitSummaryLimit() ( + seen[sha] = true + shas.append(sha) + ) + ) + return shas +) + +def commitSummaryCacheLimit() number ( + return 2000 +) + +def commitSummaryRetryMs() number ( + return 3600000 +) + +def cachedCommitSummary(object cached, string sha, number now) object ( + if !cached.contains(sha) or cached[sha] == null ( + return {} + ) + object entry = cached[sha].assertElse(object, {}) + if entry.contains("ok") and entry.ok == true ( + return entry + ) + if entry.contains("failedAt") and now - entry.failedAt.toNum() < commitSummaryRetryMs() ( + return {ok: false} + ) + return {} +) + +def mergedCommitSummaryCache(object cached, object computed) object ( + object merged = cached + if cached.len + computed.len > commitSummaryCacheLimit() ( + merged = {} + ) + array keys = computed.getKeys() + for i keys.len ( + string sha = keys[i].toStr() + merged[sha] = computed[sha] + ) + return merged +) diff --git a/src/git/commit-summary-cache.test.osl b/src/git/commit-summary-cache.test.osl new file mode 100644 index 0000000..f3cca39 --- /dev/null +++ b/src/git/commit-summary-cache.test.osl @@ -0,0 +1,34 @@ +import "std:testing" +import "std:regex" +import "./commit-summary-cache.osl" + +string first = "84223eef0258932ae0bf0bcb885ecb252431f6ec" +string second = "ef2bedd84c4a6403078ab088c795fae166ea9baf" +array parsed = requestedCommitShas(first ++ ", nothex," ++ first.toUpper() ++ "," ++ second ++ "," ++ first) +testing.assert(parsed.len == 2, "invalid, uppercase and repeated shas are dropped") +testing.assert(parsed[1] == first and parsed[2] == second, "shas keep their requested order") + +string many = "" +for i 60 ( + string hex = i.toStr().hashSHA256().trim(1, 40) + many ++= hex ++ "," +) +testing.assert(requestedCommitShas(many).len == commitSummaryLimit(), "at most fifty shas are summarised per request") + +object cached = {} +cached[first] = {ok: true, sha: first} +cached[second] = {ok: false, failedAt: 1000} +testing.assert(cachedCommitSummary(cached, first, 5000).ok == true, "stored summaries are reused") +testing.assert(cachedCommitSummary(cached, second, 2000).ok == false, "a recent failure is not retried") +testing.assert(!cachedCommitSummary(cached, second, 1000 + commitSummaryRetryMs()).contains("ok"), "an old failure is retried") +testing.assert(!cachedCommitSummary(cached, "1" ++ first.trim(2, 40), 5000).contains("ok"), "unknown shas need computing") + +object computed = {} +computed["new"] = {ok: true} +object merged = mergedCommitSummaryCache(cached, computed) +testing.assert(merged.len == 3 and merged["new"].ok == true, "new summaries are added to the cache") +object full = {} +for i commitSummaryCacheLimit() ( + full["k" ++ i.toStr()] = {ok: true} +) +testing.assert(mergedCommitSummaryCache(full, computed).len == 1, "a full cache starts again from this request") diff --git a/src/git/git-inspection.osl b/src/git/git-inspection.osl index 3f54185..8751153 100644 --- a/src/git/git-inspection.osl +++ b/src/git/git-inspection.osl @@ -286,29 +286,16 @@ def handleGetCommitFile(*serve.Context c) ( gitInspectionResponse(c, res.project.assert(object), c.param("sha"), "file", (c.query("path") ?? "")) ) -def commitSummaryLimit() number ( - return 50 -) - -def requestedCommitShas(string raw) array ( - array shas = [] - object seen = {} - for entry in raw.split(",") ( - string sha = entry.toStr().trim() - if validGitObjectId(sha) and !seen.contains(sha) and shas.len < commitSummaryLimit() ( - seen[sha] = true - shas.append(sha) - ) - ) - return shas -) - def commitSummaryCacheDir() string ( return tmpDir ++ "git-summaries/" ) +def commitSummaryCacheVersion() string ( + return "s1" +) + def commitSummaryCacheName(object project) string ( - return gitInspectionCacheVersion() ++ "." ++ project.id.toStr().hashSHA256() ++ ".json" + return commitSummaryCacheVersion() ++ "." ++ project.id.toStr().hashSHA256() ++ ".json" ) def readCommitSummaryCache(string cachePath) object ( @@ -325,22 +312,28 @@ def readCommitSummaryCache(string cachePath) object ( def computeCommitSummary(string workspacePath, string sha, string allowedHeads) object ( auto parsed = json.parse(gitinspection.Inspect(workspacePath, sha, "summary", "", allowedHeads), {type: "object"}) if parsed.isErr() ( - return {} + return {ok: false, failedAt: timestamp} ) object summary = parsed.unwrap().assert(object) if !summary.contains("ok") or summary.ok != true ( - return {} + return {ok: false, failedAt: timestamp} ) return summary ) -def writeCommitSummaryCache(string cachePath, object cached) ( +def storeCommitSummaries(string cacheDir, string cacheName, object computed) ( + string cachePath = cacheDir ++ cacheName + string lockName = "git-summaries-" ++ cacheName + sync.lock(lockName) + defer sync.unlock(lockName) + object cached = mergedCommitSummaryCache(readCommitSummaryCache(cachePath), computed) string temporaryPath = cachePath ++ ".tmp." ++ randomString(8) if fs.writeFile(temporaryPath, json.stringify(cached)) ( if !fs.rename(temporaryPath, cachePath) ( void fs.remove(temporaryPath) ) ) + pruneGitInspectionCache(cacheDir, cacheName) ) def handleGetCommitSummaries(*serve.Context c) ( @@ -358,50 +351,43 @@ def handleGetCommitSummaries(*serve.Context c) ( ) array shas = requestedCommitShas((c.query("shas") ?? "")) object summaries = {} - if shas.len == 0 ( - c.json(200, {ok: true, summaries: summaries}) - return - ) string allowedHeads = projectGitAllowedHeadsString(project) - if allowedHeads == "" ( + if shas.len == 0 or allowedHeads == "" ( c.json(200, {ok: true, summaries: summaries}) return ) string cacheDir = commitSummaryCacheDir() void fs.mkdir(cacheDir, {recursive: true}) string cacheName = commitSummaryCacheName(project) - string cachePath = cacheDir ++ cacheName - string lockName = "git-summaries-" ++ cacheName - sync.lock(lockName) - defer sync.unlock(lockName) - object cached = readCommitSummaryCache(cachePath) - boolean changed = false + object cached = readCommitSummaryCache(cacheDir ++ cacheName) + object computed = {} string workspacePath = "" + boolean workspaceMissing = false for i shas.len ( string sha = shas[i].toStr() if projectRecordsCommit(project, sha) ( - if cached.contains(sha) and cached[sha] != null ( - summaries[sha] = cached[sha] - ) else ( + object entry = cachedCommitSummary(cached, sha, timestamp) + if entry.contains("ok") ( + if entry.ok == true ( + summaries[sha] = entry + ) + ) else if !workspaceMissing ( if workspacePath == "" ( workspacePath = cachedProjectWorkspacePath(project) - if workspacePath == "" ( - c.notFound("workspace not found") - return - ) + workspaceMissing = workspacePath == "" ) - object summary = computeCommitSummary(workspacePath, sha, allowedHeads) - if summary.contains("ok") ( - summaries[sha] = summary - cached[sha] = summary - changed = true + if !workspaceMissing ( + object summary = computeCommitSummary(workspacePath, sha, allowedHeads) + computed[sha] = summary + if summary.ok == true ( + summaries[sha] = summary + ) ) ) ) ) - if changed ( - writeCommitSummaryCache(cachePath, cached) - pruneGitInspectionCache(cacheDir, cacheName) + if computed.len > 0 ( + storeCommitSummaries(cacheDir, cacheName, computed) ) c.json(200, {ok: true, summaries: summaries}) ) From b9616840010a821d558a1df7d7804105188e1d3c Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:51:20 +0000 Subject: [PATCH 5/5] Retry failed commit summaries sooner and count only new cache entries --- src/git/commit-summary-cache.osl | 12 +++++++++--- src/git/commit-summary-cache.test.osl | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/git/commit-summary-cache.osl b/src/git/commit-summary-cache.osl index a39af2f..7eedf5c 100644 --- a/src/git/commit-summary-cache.osl +++ b/src/git/commit-summary-cache.osl @@ -20,7 +20,7 @@ def commitSummaryCacheLimit() number ( ) def commitSummaryRetryMs() number ( - return 3600000 + return 600000 ) def cachedCommitSummary(object cached, string sha, number now) object ( @@ -39,10 +39,16 @@ def cachedCommitSummary(object cached, string sha, number now) object ( def mergedCommitSummaryCache(object cached, object computed) object ( object merged = cached - if cached.len + computed.len > commitSummaryCacheLimit() ( + array keys = computed.getKeys() + number added = 0 + for i keys.len ( + if !cached.contains(keys[i].toStr()) ( + added += 1 + ) + ) + if cached.len + added > commitSummaryCacheLimit() ( merged = {} ) - array keys = computed.getKeys() for i keys.len ( string sha = keys[i].toStr() merged[sha] = computed[sha] diff --git a/src/git/commit-summary-cache.test.osl b/src/git/commit-summary-cache.test.osl index f3cca39..872a0a3 100644 --- a/src/git/commit-summary-cache.test.osl +++ b/src/git/commit-summary-cache.test.osl @@ -32,3 +32,6 @@ for i commitSummaryCacheLimit() ( full["k" ++ i.toStr()] = {ok: true} ) testing.assert(mergedCommitSummaryCache(full, computed).len == 1, "a full cache starts again from this request") +object retried = {} +retried["k1"] = {ok: true} +testing.assert(mergedCommitSummaryCache(full, retried).len == commitSummaryCacheLimit(), "replacing stored entries does not count toward the limit")