oficina / mapa Public

Review L2, L3, L11: Recently edited is yours only and skips link transactions; sealed pins are one length

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Summary

Fable's Phase 1 review (6e3aa6b): Review L2, L3, L11: Recently edited is yours only and skips link transactions; sealed pins are one length
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 4352e1750b337275db16a2cf67bd59d1adaa2090 parent 4477ae4
2 files changed, +51 −16
  • internal/mapa/pins.go +24 −7
  • internal/mapa/recent.go +27 −9
diff --git a/internal/mapa/pins.go b/internal/mapa/pins.go
index 3c82cd8..9ef7fd4 100644
--- a/internal/mapa/pins.go
+++ b/internal/mapa/pins.go
@@ -2,7 +2,7 @@ package mapa
import (
"context"
- "encoding/json"
+ "encoding/binary"
"errors"
"net/http"
"slices"
@@ -48,8 +48,29 @@ func (store *Store) openPins(sealed []byte) ([]int64, error) {
if err != nil {
return nil, err
}
+ if len(plain) != pinBytes {
+ return nil, errors.New("mapa: pins of the wrong length")
+ }
var ids []int64
- return ids, json.Unmarshal(plain, &ids)
+ for at := 0; at < pinBytes; at += 8 {
+ if id := int64(binary.BigEndian.Uint64(plain[at:])); id != 0 {
+ ids = append(ids, id)
+ }
+ }
+ return ids, nil
+}
+
+// pinBytes is the sealed list's plaintext length, always: maxPins
+// slots of eight bytes, empty ones zero, so the ciphertext's length
+// does not say how many pages a person pinned (review L11).
+const pinBytes = maxPins * 8
+
+func pinPlain(ids []int64) []byte {
+ plain := make([]byte, pinBytes)
+ for at, id := range ids {
+ binary.BigEndian.PutUint64(plain[at*8:], uint64(id))
+ }
+ return plain
}
// SetPin pins or unpins a page the person may open.
@@ -90,11 +111,7 @@ func repin(ids []int64, pageID int64, pinned bool) ([]int64, error) {
}
func (tx *Tx) savePins(memberID int64, ids []int64) error {
- plain, err := json.Marshal(ids)
- if err != nil {
- return err
- }
- sealed, err := tx.store.sealer.Seal(seal.PurposePins, plain)
+ sealed, err := tx.store.sealer.Seal(seal.PurposePins, pinPlain(ids))
if err != nil {
return err
}
diff --git a/internal/mapa/recent.go b/internal/mapa/recent.go
index e78cf7e..7cd9a10 100644
--- a/internal/mapa/recent.go
+++ b/internal/mapa/recent.go
@@ -13,8 +13,10 @@ import (
const recentCount = 6
// recentVerbs are the writes that count as editing a page. Bulk link
-// edits on team pages log their own verbs and do not count (§8).
-var recentVerbs = []string{VerbCreated, VerbEdited, VerbReverted}
+// edits on team pages log their own verbs and do not count (§8); they
+// are read only to recognise their transaction.
+var recentVerbs = []string{VerbCreated, VerbEdited, VerbReverted,
+ VerbRelinked, VerbMarked}
// recentEdits is the page ids the person last wrote in, newest first,
// leaving out bulk edits: a transaction that logged more than one
@@ -30,16 +32,12 @@ func (store *Store) recentEdits(ctx context.Context,
if err != nil {
return nil, err
}
- edited := map[int64]int{}
- for _, row := range rows {
- if row.Verb == VerbEdited {
- edited[row.At.UnixNano()]++
- }
- }
+ bulk := bulkWrites(rows)
var ids []int64
seen := map[int64]bool{}
for _, row := range rows {
- if (row.Verb == VerbEdited && edited[row.At.UnixNano()] > 1) ||
+ if row.Verb == VerbRelinked || row.Verb == VerbMarked ||
+ (row.Verb == VerbEdited && bulk[row.At.UnixNano()]) ||
seen[row.ObjectID] {
continue
}
@@ -49,6 +47,26 @@ func (store *Store) recentEdits(ctx context.Context,
return ids, nil
}
+// bulkWrites is each transaction (one actor, one at) that edited more
+// than one page, or that a link verb also names: "Update links" on
+// private pages logs "edited", and in a transaction with a team page it
+// sits beside "relinked" (review L3).
+func bulkWrites(rows []Event) map[int64]bool {
+ edited := map[int64]int{}
+ bulk := map[int64]bool{}
+ for _, row := range rows {
+ at := row.At.UnixNano()
+ switch row.Verb {
+ case VerbEdited:
+ edited[at]++
+ bulk[at] = bulk[at] || edited[at] > 1
+ case VerbRelinked, VerbMarked:
+ bulk[at] = true
+ }
+ }
+ return bulk
+}
+
// sideLists are Pinned and Recently edited for the viewer. A failure to
// read them leaves them out; the page itself still draws.
func (app *app) sideLists(request *http.Request,