tests run (but not pass) and fine-tuning (specially tag filters) on filter_easyjson.go

This commit is contained in:
fiatjaf
2023-04-16 16:12:42 -03:00
parent 0a3e898c2f
commit c42059f4b4
12 changed files with 116 additions and 129 deletions
+74 -92
View File
@@ -4,6 +4,7 @@ package nostr
import (
json "encoding/json"
easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"
@@ -26,6 +27,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
in.Skip()
return
}
out.Tags = make(TagMap)
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
@@ -36,7 +38,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
continue
}
switch key {
case "IDs":
case "ids":
if in.IsNull() {
in.Skip()
out.IDs = nil
@@ -44,7 +46,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
in.Delim('[')
if out.IDs == nil {
if !in.IsDelim(']') {
out.IDs = make([]string, 0, 4)
out.IDs = make([]string, 0, 20)
} else {
out.IDs = []string{}
}
@@ -59,7 +61,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
}
in.Delim(']')
}
case "Kinds":
case "kinds":
if in.IsNull() {
in.Skip()
out.Kinds = nil
@@ -82,7 +84,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
}
in.Delim(']')
}
case "Authors":
case "authors":
if in.IsNull() {
in.Skip()
out.Authors = nil
@@ -90,7 +92,7 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
in.Delim('[')
if out.Authors == nil {
if !in.IsDelim(']') {
out.Authors = make([]string, 0, 4)
out.Authors = make([]string, 0, 40)
} else {
out.Authors = []string{}
}
@@ -105,53 +107,56 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
}
in.Delim(']')
}
case "Tags":
case "since":
if in.IsNull() {
in.Skip()
out.Since = nil
} else {
in.Delim('{')
out.Tags = make(TagMap)
for !in.IsDelim('}') {
key := string(in.String())
in.WantColon()
var v4 []string
if in.IsNull() {
in.Skip()
v4 = nil
} else {
in.Delim('[')
if v4 == nil {
if !in.IsDelim(']') {
v4 = make([]string, 0, 4)
} else {
v4 = []string{}
}
} else {
v4 = (v4)[:0]
}
for !in.IsDelim(']') {
var v5 string
v5 = string(in.String())
v4 = append(v4, v5)
in.WantComma()
}
in.Delim(']')
}
(out.Tags)[key] = v4
in.WantComma()
if out.Since == nil {
out.Since = new(Timestamp)
}
in.Delim('}')
*out.Since = Timestamp(in.Int64())
}
case "Since":
out.Since = Timestamp(in.Int64())
case "Until":
out.Until = Timestamp(in.Int64())
case "Limit":
case "until":
if in.IsNull() {
in.Skip()
out.Until = nil
} else {
if out.Until == nil {
out.Until = new(Timestamp)
}
*out.Until = Timestamp(in.Int64())
}
case "limit":
out.Limit = int(in.Int())
case "Search":
case "search":
out.Search = string(in.String())
default:
in.SkipRecursive()
if len(key) > 1 && key[0] == '#' {
tagValues := make([]string, 0, 40)
if !in.IsNull() {
in.Delim('[')
if out.Authors == nil {
if !in.IsDelim(']') {
tagValues = make([]string, 0, 4)
} else {
tagValues = []string{}
}
} else {
tagValues = (tagValues)[:0]
}
for !in.IsDelim(']') {
var v3 string
v3 = string(in.String())
tagValues = append(tagValues, v3)
in.WantComma()
}
in.Delim(']')
}
out.Tags[key[1:]] = tagValues
} else {
in.SkipRecursive()
}
}
in.WantComma()
}
@@ -160,107 +165,84 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
in.Consumed()
}
}
func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"IDs\":"
const prefix string = ",\"ids\":"
out.RawString(prefix[1:])
if in.IDs == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v6, v7 := range in.IDs {
if v6 > 0 {
for v4, v5 := range in.IDs {
if v4 > 0 {
out.RawByte(',')
}
out.String(string(v7))
out.String(string(v5))
}
out.RawByte(']')
}
}
{
const prefix string = ",\"Kinds\":"
const prefix string = ",\"kinds\":"
out.RawString(prefix)
if in.Kinds == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v8, v9 := range in.Kinds {
if v8 > 0 {
for v6, v7 := range in.Kinds {
if v6 > 0 {
out.RawByte(',')
}
out.Int(int(v9))
out.Int(int(v7))
}
out.RawByte(']')
}
}
{
const prefix string = ",\"Authors\":"
const prefix string = ",\"authors\":"
out.RawString(prefix)
if in.Authors == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v10, v11 := range in.Authors {
if v10 > 0 {
for v8, v9 := range in.Authors {
if v8 > 0 {
out.RawByte(',')
}
out.String(string(v11))
out.String(string(v9))
}
out.RawByte(']')
}
}
{
const prefix string = ",\"Tags\":"
const prefix string = ",\"since\":"
out.RawString(prefix)
if in.Tags == nil && (out.Flags&jwriter.NilMapAsEmpty) == 0 {
out.RawString(`null`)
if in.Since == nil {
out.RawString("null")
} else {
out.RawByte('{')
v12First := true
for v12Name, v12Value := range in.Tags {
if v12First {
v12First = false
} else {
out.RawByte(',')
}
out.String(string(v12Name))
out.RawByte(':')
if v12Value == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v13, v14 := range v12Value {
if v13 > 0 {
out.RawByte(',')
}
out.String(string(v14))
}
out.RawByte(']')
}
}
out.RawByte('}')
out.Int64(int64(*in.Since))
}
}
{
const prefix string = ",\"Since\":"
const prefix string = ",\"until\":"
out.RawString(prefix)
out.Int64(int64(in.Since))
if in.Until == nil {
out.RawString("null")
} else {
out.Int64(int64(*in.Until))
}
}
{
const prefix string = ",\"Until\":"
out.RawString(prefix)
out.Int64(int64(in.Until))
}
{
const prefix string = ",\"Limit\":"
const prefix string = ",\"limit\":"
out.RawString(prefix)
out.Int(int(in.Limit))
}
{
const prefix string = ",\"Search\":"
const prefix string = ",\"search\":"
out.RawString(prefix)
out.String(string(in.Search))
}