Add SQLite listing store with deterministic conflict rules
- Put verifies listings and keeps only the newest version per (author, id); equal seq resolves to the smaller hash so replicas converge - Tombstones are stored so old versions cannot be resurrected - Search by geohash prefix, kind, category, price, area, rooms - Expire removes listings and tombstones past their lifetime Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+17
-11
@@ -10,6 +10,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
@@ -301,21 +302,26 @@ func validGeohash(g string) error {
|
||||
if len(g) != GeohashPrecision {
|
||||
return fmt.Errorf("listing: geohash must have precision %d", GeohashPrecision)
|
||||
}
|
||||
for i := 0; i < len(g); i++ {
|
||||
found := false
|
||||
for j := 0; j < len(geohashAlphabet); j++ {
|
||||
if g[i] == geohashAlphabet[j] {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return errors.New("listing: invalid geohash character")
|
||||
}
|
||||
if !ValidGeohashPrefix(g) {
|
||||
return errors.New("listing: invalid geohash character")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidGeohashPrefix reports whether p is a non-empty geohash prefix of at
|
||||
// most GeohashPrecision characters from the geohash alphabet.
|
||||
func ValidGeohashPrefix(p string) bool {
|
||||
if len(p) == 0 || len(p) > GeohashPrecision {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(p); i++ {
|
||||
if !strings.ContainsRune(geohashAlphabet, rune(p[i])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func validPeerID(s string) bool {
|
||||
if len(s) < 8 || len(s) > 128 {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user