Implement in-memory Store with typed Mutation interface and pre-validation #9
Labels
No labels
area/api
area/bridge
area/db
area/docs
area/ops
area/web
kind/bug
kind/chore
kind/feature
kind/spike
prio/p0
prio/p1
prio/p2
prio/p3
status/blocked
status/decision
status/needs-info
type/question
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: sscoble/posts#9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
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?
Why
The hot store is in-memory (posts#1 decision). All writes go through a typed
MutationwhoseValidate()runs without holding a lock; only validated mutations acquire a lock toApply(). The lock-region is adaptive (see #10).Files
api/store.go(refactor — drop lib/pq; in-memory maps + indexes)api/mutation.go(new —Mutationinterface,Validate/Applysplit)api/mutations_*.go(one file per mutation:create_post.go,add_comment.go,bump_post.go, etc.)api/index.go(new — sorted indexes,postsByBumpedAt,commentsByPostPath,mentionsByMentioned)MutationshapeEach mutation is a typed struct (not a string-discriminated union). Validate is deterministic and side-effect-free. Apply is the only place that mutates state. The lock parameter is the actual lock acquired, so Apply can release it explicitly if needed (rare).
Store state (in-memory)
Memory management (Scott: "we need to be very careful")
sync.Poolfor*Post,*Comment— high churn on comment creationcommentsByPostPath(cap at e.g. 10k comments per post; spill to cold)unsafe.Sizeofwalk forStore.MemUsage()— feeds #11's measurementintern.Getfor repeated values (channel slugs, author IDs) — fewer allocsAcceptance
docs/API.mdwork against the in-memory storeValidateruns without acquiring any application lock (only the immutable types)Applyis the only path that mutates stateStore.MemUsage()reports live bytes per typego test ./...passes; race detector clean (go test -race ./...)✅ Acceptance Verification — c2326 (2026-07-30)
Cycle: c2326 cron dispatch closure check
Verdict: PASS — implementation complete, all tests pass.
In-memory Store + typed Mutation interface — mutation.go defines Mutation interface (Validate/Apply/AffectedAuthors/Kind). store.go implements in-memory store with sync.Pool, string interning, bounded comment index. go test ./... PASS. Implementation complete.
Closing as complete.