chore: fix twt hash

This commit is contained in:
xuu
2025-03-30 21:14:11 -06:00
parent fb957ed25d
commit fc762f3bf3
4 changed files with 16 additions and 105 deletions

14
feed.go
View File

@@ -3,10 +3,10 @@ package main
import (
"cmp"
"context"
"crypto/sha3"
"database/sql"
"database/sql/driver"
"fmt"
"hash/fnv"
"io"
"iter"
"net/http"
@@ -378,6 +378,7 @@ func storeRegistry(ctx context.Context, db db, in io.Reader) error {
twters := make(map[string]string)
args := make([]any, 0, 1024*16)
i := 0
for line := range lextwt.IterRegistry(in) {
twt, ok := line.(*lextwt.Twt)
if !ok {
@@ -431,6 +432,8 @@ func storeRegistry(ctx context.Context, db db, in io.Reader) error {
)
if len(args) >= 16*1022 {
i+=len(args)
fmt.Println("store", i/7, i)
tx, err := db.BeginTx(ctx, nil)
if err != nil {
return err
@@ -560,15 +563,10 @@ func (n TwtTime) Value() (driver.Value, error) {
}
func makeULID(twt types.Twt) ulid.ULID {
h64 := fnv.New64a()
h16 := fnv.New32a()
text := []byte(fmt.Sprintf("%+l", twt))
b := make([]byte, 10)
copy(b, h16.Sum(text)[:2])
copy(b[2:], h64.Sum(text))
text := fmt.Appendf(nil, "%s\t%+l", cmp.Or(twt.Twter().HashingURI, twt.Twter().URI), twt)
u := ulid.ULID{}
u.SetTime(ulid.Timestamp(twt.Created()))
u.SetEntropy(b)
u.SetEntropy(sha3.SumSHAKE128(text, 10))
return u
}