fix jsonpath-based taq query.

This commit is contained in:
fiatjaf 2021-11-28 16:55:39 -03:00
parent 7a3e07c5b2
commit 5a797d2c65
4 changed files with 7 additions and 8 deletions

5
go.mod
View File

@ -1,15 +1,14 @@
module github.com/fiatjaf/nostr-relay
module github.com/fiatjaf/relayer
go 1.15
require (
github.com/fiatjaf/go-nostr v0.1.1
github.com/fiatjaf/go-nostr v0.1.4
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/jmoiron/sqlx v1.3.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.8.0
github.com/mattn/go-sqlite3 v1.14.6
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.20.0
)

4
go.sum
View File

@ -17,8 +17,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fiatjaf/bip340 v1.0.0 h1:mpwbm+0KC9BXB/7/pnac4e4N1TiuppyEVXxtVAXj75k=
github.com/fiatjaf/bip340 v1.0.0/go.mod h1:MxAz+5FQUTW4OT2gnCBC6Our486wmqf72ykZIrh7+is=
github.com/fiatjaf/go-nostr v0.1.1 h1:mMUn+Dr0QfhM1JuBHcGvvV0ON/tkinvOfXF8Yh825Xc=
github.com/fiatjaf/go-nostr v0.1.1/go.mod h1:Zwa4KwVMy3gLoMbbrH+NOZvqmrDADCIV+C67ew7VEqs=
github.com/fiatjaf/go-nostr v0.1.4 h1:OicdiaKBgt8UaI3/Eh+TIcC1uuMlXJMl+5IU7QqmgYo=
github.com/fiatjaf/go-nostr v0.1.4/go.mod h1:Zwa4KwVMy3gLoMbbrH+NOZvqmrDADCIV+C67ew7VEqs=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

View File

@ -29,4 +29,4 @@ CREATE UNIQUE INDEX IF NOT EXISTS pubkeytimeidx ON event (pubkey, created_at);
return db, nil
}
const relatedEventsCondition = `tags @@ '$[*][1] == "' || ? || '"'`
const tagConditions = `jsonb_path_match(tags, '$[*][1] == $value', jsonb_build_object('value', ?::text))`

View File

@ -55,12 +55,12 @@ func queryEvents(filter *filter.EventFilter) (events []event.Event, err error) {
}
if filter.TagEvent != "" {
conditions = append(conditions, relatedEventsCondition)
conditions = append(conditions, tagConditions)
params = append(params, filter.TagEvent)
}
if filter.TagProfile != "" {
conditions = append(conditions, relatedEventsCondition)
conditions = append(conditions, tagConditions)
params = append(params, filter.TagProfile)
}