use @mmalmi json string preparsing speedup for duplicate events
- get rid of "nonUnique" variants of subMany as we can now relay on CheckDuplicate to track relays. - add global pool tracker duplicateMiddleware.
This commit is contained in:
34
helpers.go
34
helpers.go
@@ -1,6 +1,7 @@
|
||||
package nostr
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -117,3 +118,36 @@ func isLowerHex(thing string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func extractSubID(jsonStr []byte) string {
|
||||
// look for "EVENT" pattern
|
||||
start := bytes.Index(jsonStr, []byte(`"EVENT"`))
|
||||
if start == -1 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// move to the next quote
|
||||
offset := bytes.Index(jsonStr[start+7:], []byte{'"'})
|
||||
start += 7 + offset + 1
|
||||
|
||||
// find the ending quote
|
||||
end := bytes.Index(jsonStr[start:], []byte{'"'})
|
||||
|
||||
// get the contents
|
||||
return string(jsonStr[start : start+end])
|
||||
}
|
||||
|
||||
func extractEventID(jsonStr []byte) string {
|
||||
// look for "id": pattern
|
||||
start := bytes.Index(jsonStr, []byte(`"id":`))
|
||||
if start == -1 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// move to the next quote
|
||||
offset := bytes.Index(jsonStr[start+4:], []byte{'"'})
|
||||
start += 4 + offset + 1
|
||||
|
||||
// get 64 characters of the id
|
||||
return string(jsonStr[start : start+64])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user