From ca03dc60f7d457ad9e26e7ec0437fa8ac91057ec Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 29 Jun 2025 22:20:30 -0300 Subject: [PATCH] eventstore/lmdb,mmm: fix key size for "a"-style tags. --- eventstore/lmdb/helpers.go | 8 ++++---- eventstore/mmm/helpers.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eventstore/lmdb/helpers.go b/eventstore/lmdb/helpers.go index dc87f95..ad81416 100644 --- a/eventstore/lmdb/helpers.go +++ b/eventstore/lmdb/helpers.go @@ -147,7 +147,7 @@ func (b *LMDBBackend) getTagIndexPrefix(tagName string, tagValue string) (lmdb.D // if it's 32 bytes as hex, save it as bytes if len(tagValue) == 64 { - // but we actually only use the first 8 bytes, with tag name prefix + // but we actually only use the first 8 bytes, with letter (tag name) prefix k = make([]byte, 1+8+4) if _, err := hex.Decode(k[1:1+8], []byte(tagValue[0:8*2])); err == nil { k[0] = letterPrefix @@ -157,10 +157,10 @@ func (b *LMDBBackend) getTagIndexPrefix(tagName string, tagValue string) (lmdb.D } } - // if it looks like an "a" tag, index it in this special format (no tag name prefix for special indexes) + // if it looks like an "a" tag, index it in this special format, with letter (tag name) prefix spl := strings.Split(tagValue, ":") if len(spl) == 3 && len(spl[1]) == 64 { - k = make([]byte, 1+2+8+30) + k = make([]byte, 1+2+8+30+4) if _, err := hex.Decode(k[1+2:1+2+8], []byte(spl[1][0:8*2])); err == nil { if kind, err := strconv.ParseUint(spl[0], 10, 16); err == nil { k[0] = letterPrefix @@ -175,7 +175,7 @@ func (b *LMDBBackend) getTagIndexPrefix(tagName string, tagValue string) (lmdb.D } } - // index whatever else as a md5 hash of the contents with tag name prefix + // index whatever else as a md5 hash of the contents, with letter (tag name) prefix h := md5.New() h.Write([]byte(tagValue)) k = make([]byte, 1, 1+16+4) diff --git a/eventstore/mmm/helpers.go b/eventstore/mmm/helpers.go index 4add03a..37d51e0 100644 --- a/eventstore/mmm/helpers.go +++ b/eventstore/mmm/helpers.go @@ -134,7 +134,7 @@ func (il *IndexingLayer) getTagIndexPrefix(tagName string, tagValue string) (lmd // if it's 32 bytes as hex, save it as bytes if len(tagValue) == 64 { - // but we actually only use the first 8 bytes, with tag name prefix + // but we actually only use the first 8 bytes, with letter (tag name) prefix k = make([]byte, 1+8+4) if _, err := hex.Decode(k[1:1+8], []byte(tagValue[0:8*2])); err == nil { k[0] = letterPrefix @@ -144,10 +144,10 @@ func (il *IndexingLayer) getTagIndexPrefix(tagName string, tagValue string) (lmd } } - // if it looks like an "a" tag, index it in this special format (no tag name prefix for special indexes) + // if it looks like an "a" tag, index it in this special format, with letter (tag name) prefix spl := strings.Split(tagValue, ":") if len(spl) == 3 && len(spl[1]) == 64 { - k = make([]byte, 1+2+8+30) + k = make([]byte, 1+2+8+30+4) if _, err := hex.Decode(k[1+2:1+2+8], []byte(spl[1][0:8*2])); err == nil { if kind, err := strconv.ParseUint(spl[0], 10, 16); err == nil { k[0] = letterPrefix @@ -162,7 +162,7 @@ func (il *IndexingLayer) getTagIndexPrefix(tagName string, tagValue string) (lmd } } - // index whatever else as utf-8, but limit it to 40 bytes, with tag name prefix + // index whatever else as utf-8, but limit it to 40 bytes, with letter (tag name) prefix k = make([]byte, 1+40+4) k[0] = letterPrefix n := copy(k[1:1+40], tagValue)