eventstore/lmdb,mmm: fix key size for "a"-style tags.

This commit is contained in:
fiatjaf
2025-06-29 22:20:30 -03:00
parent 5f4a966d45
commit ca03dc60f7
2 changed files with 8 additions and 8 deletions

View File

@@ -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)

View File

@@ -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)