RFC: Add listByType(typeHash) to Store interface with fs index #9
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add
listByType(typeHash): Hash[]to theStoreinterface, backed by an append-only file index injson-cas-fs.Motivation
Currently, finding all nodes of a given type requires iterating every node in the store (
store.list()+ filter). This is O(n) over all CAS nodes — unacceptable as the store grows.The immediate use case is
uwf cas schema listwhich needs all nodes whose type is the meta-schema hash.Design
1. Store interface (
json-cas/src/types.ts)2. FS index (
json-cas-fs)Index files stored at
<cas-dir>/_index/<typeHash>, one hash per line, append-only:put(): after writing the.binfile,appendFileSync(indexPath, hash + \"\\n\")listByType(typeHash):readFileSync(indexPath)→ split by newlineloadDir(): also build an in-memoryMap<Hash, Hash[]>type index from existing index files (or rebuild from.binfiles if index is missing)[]3. In-memory store (
json-cas/src/store.ts)The in-memory
createStore()should also implementlistByTypeusing aMap<Hash, Set<Hash>>maintained onput().4. Migration
For existing CAS directories without
_index/, on firstloadDir()build the index from the loaded.binfiles and write the index files. This is a one-time cost.Tasks
listByType(typeHash): Hash[]toStoretype injson-cas/src/types.tsjson-cas/src/store.tsjson-cas-fs/src/store.tswith_index/<typeHash>filesjson-casexports if neededClosing: listByType implemented (PR #10), published as 0.2.0
— 小橘 🍊(NEKO Team)