-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support NIP-45 #58
support NIP-45 #58
Conversation
I'll add tests tonight. |
If you think it's fine we can merge it without tests. |
query = sqlx.Rebind(sqlx.BindType("postgres"), `SELECT | ||
COUNT(*) | ||
FROM event WHERE `+ | ||
strings.Join(conditions, " AND ")+ | ||
" ORDER BY created_at DESC LIMIT ?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query = sqlx.Rebind(sqlx.BindType("postgres"), `SELECT | |
COUNT(*) | |
FROM event WHERE `+ | |
strings.Join(conditions, " AND ")+ | |
" ORDER BY created_at DESC LIMIT ?") | |
query = sqlx.Rebind(sqlx.BindType("postgres"), `SELECT COUNT(*) FROM event WHERE `+ strings.Join(conditions, " AND ") + " ORDER BY created_at DESC LIMIT ?") |
err := rows.Scan(&evt.ID, &evt.PubKey, ×tamp, | ||
&evt.Kind, &evt.Tags, &evt.Content, &evt.Sig) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err := rows.Scan(&evt.ID, &evt.PubKey, ×tamp, | |
&evt.Kind, &evt.Tags, &evt.Content, &evt.Sig) | |
if err != nil { | |
if err = rows.Scan(&evt.ID, &evt.PubKey, ×tamp, &evt.Kind, &evt.Tags, &evt.Content, &evt.Sig); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a :=
err = b.DB.QueryRow(query, params...).Scan(&count) | ||
if err != nil && err != sql.ErrNoRows { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = b.DB.QueryRow(query, params...).Scan(&count) | |
if err != nil && err != sql.ErrNoRows { | |
if err = b.DB.QueryRow(query, params...).Scan(&count); err != nil && err != sql.ErrNoRows { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a :=
Co-authored-by: Isaque Veras <46972789+isaqueveras@users.noreply.github.com>
storage/postgresql/query.go
Outdated
@@ -51,8 +51,7 @@ func (b PostgresBackend) CountEvents(ctx context.Context, filter *nostr.Filter) | |||
} | |||
|
|||
var count int64 | |||
err = b.DB.QueryRow(query, params...).Scan(&count) | |||
if err != nil && err != sql.ErrNoRows { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this should be a :=
fixed tests |
Ready to merge? |
yes. |
} | ||
|
||
ws.WriteJSON([]interface{}{"COUNT", id, map[string]int64{"count": total}}) | ||
setListener(id, ws, filters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct.
NIP-45 and its use of the word 'subcription-id' instead of 'request-id' I think confuses things.
setListener here is for setting this id as something that is listening on an open subscription.
COUNT is a request w/ a single and immediate response (w/ ID).
The setListener call should be removed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. could you please send PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, it's literally just removing line 240. Isn't this your PR though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just suggesting everyone's contribution. If you don't have a time to do, I will fix it. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented NIP-45 supported storages. but not supported for elasticsearch.