Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea cloud renders know a project's footage by the file, not its path: a thread started again links the same files into a new folder (StreetTalk's restart hard-linked 1.9 GB of interviews), and keyed by path they were hashed again before its first render. media.ts keys its hash cache by device and inode, with size and time

shinyobjectzafaeaa0a7a80
diff --git a/sdk/cloud/server/media.ts b/sdk/cloud/server/media.ts
index 3fbc0827..d82b754a 100644
--- a/sdk/cloud/server/media.ts
+++ b/sdk/cloud/server/media.ts
@@ -167,7 +167,9 @@ export function farmBlobs(url: string, token: string): FarmBlobs {
}
}
-/** each file's hash, kept by its path, size and time so a project's footage is hashed once, not on every render */
+/** each file's hash, kept by the file itself (its device and inode) with its size and time, so a project's footage is
+ * hashed once, not on every render, nor again in a new thread's folder that links the same files (11-25: StreetTalk's
+ * restart hard-linked its 1.9 GB of interviews into a new folder, and they were hashed again) */
function hashes(file: string) {
let known: Record<string, { size: number; mtime: number; oid: string }> = {}
try {
@@ -175,11 +177,11 @@ function hashes(file: string) {
} catch {}
let changed = false
return {
- async of(p: string, size: number, mtime: number): Promise<string> {
- const k = known[p]
+ async of(p: string, id: string, size: number, mtime: number): Promise<string> {
+ const k = known[id]
if (k && k.size === size && k.mtime === mtime) return k.oid
const oid = await sha256(p)
- known[p] = { size, mtime, oid }
+ known[id] = { size, mtime, oid }
changed = true
return oid
},
@@ -198,7 +200,7 @@ function hashes(file: string) {
* (StreetTalk's 1.9 GB of interviews went in every render's tar, even one frame's). null when the farm has no cache.
* `skip`: the tar's excludes. Links are left to the tar, as before. */
export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string) => boolean = () => false, said: (s: string) => void = () => {}, store = path.join(os.homedir(), ".cache", "raea-offload", "hashes.json")): Promise<{ media: Media[]; sent: number } | null> {
- const found: { path: string; abs: string; size: number; mtime: number }[] = []
+ const found: { path: string; abs: string; id: string; size: number; mtime: number }[] = []
const walk = (dir: string) => {
for (const e of readdirSync(dir, { withFileTypes: true })) {
const abs = path.join(dir, e.name)
@@ -208,7 +210,7 @@ export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string
else if (e.isFile()) {
const st = statSync(abs)
const ext = e.name.includes(".") ? e.name.split(".").pop()!.toLowerCase() : ""
- if (st.size >= LARGE || (st.size >= SMALL && MEDIA.has(ext))) found.push({ path: rel, abs, size: st.size, mtime: st.mtimeMs })
+ if (st.size >= LARGE || (st.size >= SMALL && MEDIA.has(ext))) found.push({ path: rel, abs, id: `${st.dev}:${st.ino}`, size: st.size, mtime: st.mtimeMs })
}
}
}
@@ -216,7 +218,7 @@ export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string
if (!found.length) return { media: [], sent: 0 }
const h = hashes(store)
const media: (Media & { abs: string })[] = []
- for (const f of found) media.push({ path: f.path, oid: await h.of(f.abs, f.size, f.mtime), size: f.size, abs: f.abs })
+ for (const f of found) media.push({ path: f.path, oid: await h.of(f.abs, f.id, f.size, f.mtime), size: f.size, abs: f.abs })
h.save()
const have = await farm.have(media.map(({ oid, size }) => ({ oid, size })))
if (!have) return null
diff --git a/sdk/cloud/test/farm-blobs.ts b/sdk/cloud/test/farm-blobs.ts
index 03da86e8..4c501ddd 100644
--- a/sdk/cloud/test/farm-blobs.ts
+++ b/sdk/cloud/test/farm-blobs.ts
@@ -5,7 +5,7 @@
// file changed since is sent again; out/ and links are left alone; a farm without the cache answers null.
import { createHash } from "node:crypto"
-import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from "node:fs"
+import { linkSync, mkdirSync, mkdtempSync, readFileSync, symlinkSync, writeFileSync } from "node:fs"
import { createServer } from "node:http"
import type { AddressInfo } from "node:net"
import { tmpdir } from "node:os"
@@ -82,6 +82,16 @@ const third = await farmInputs(root, blobs, skip, () => {}, store)
assert(third!.sent === 300 << 10 && puts === 4, `a changed file is sent again: ${third!.sent}`)
ok("a file changed since is hashed and sent again")
+// a new folder that hard-links the same footage (a thread started again) hashes nothing again
+const again = mkdtempSync(path.join(tmpdir(), "farm-blobs-linked-"))
+mkdirSync(path.join(again, "media"))
+linkSync(path.join(root, "media", "interview.MOV"), path.join(again, "media", "interview.MOV"))
+const linked = await farmInputs(again, blobs, skip, () => {}, store)
+assert(linked!.sent === 0 && linked!.media[0].oid === first!.media.find((m) => m.path === "media/interview.MOV")!.oid, "the linked file is known")
+const known = JSON.parse(readFileSync(store, "utf8")) as Record<string, unknown>
+assert(Object.keys(known).length === 4, `one entry a file (logo.png rewritten in place is the same file), not a path: ${Object.keys(known).length}`)
+ok("a new folder that links the same footage hashes and sends nothing again")
+
cache = false
assert((await farmInputs(root, blobs, skip, () => {}, store)) === null, "an older farm")
ok("a farm without the cache answers null: the media goes in the tar")