Skip to content
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

Merged
merged 7 commits into from
May 17, 2023
Merged

support NIP-45 #58

merged 7 commits into from
May 17, 2023

Conversation

mattn
Copy link
Collaborator

@mattn mattn commented May 16, 2023

implemented NIP-45 supported storages. but not supported for elasticsearch.

@mattn
Copy link
Collaborator Author

mattn commented May 16, 2023

I'll add tests tonight.

@fiatjaf
Copy link
Owner

fiatjaf commented May 16, 2023

If you think it's fine we can merge it without tests.

storage/postgresql/query.go Outdated Show resolved Hide resolved
Comment on lines +184 to +188
query = sqlx.Rebind(sqlx.BindType("postgres"), `SELECT
COUNT(*)
FROM event WHERE `+
strings.Join(conditions, " AND ")+
" ORDER BY created_at DESC LIMIT ?")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 ?")

Comment on lines +34 to +36
err := rows.Scan(&evt.ID, &evt.PubKey, &timestamp,
&evt.Kind, &evt.Tags, &evt.Content, &evt.Sig)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err := rows.Scan(&evt.ID, &evt.PubKey, &timestamp,
&evt.Kind, &evt.Tags, &evt.Content, &evt.Sig)
if err != nil {
if err = rows.Scan(&evt.ID, &evt.PubKey, &timestamp, &evt.Kind, &evt.Tags, &evt.Content, &evt.Sig); err != nil {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a :=

Comment on lines +54 to +55
err = b.DB.QueryRow(query, params...).Scan(&count)
if err != nil && err != sql.ErrNoRows {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a :=

handlers.go Outdated Show resolved Hide resolved
Co-authored-by: Isaque Veras <46972789+isaqueveras@users.noreply.github.com>
@@ -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 {
Copy link
Owner

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 :=

fiatjaf and others added 4 commits May 16, 2023 08:31
Co-authored-by: Isaque Veras <46972789+isaqueveras@users.noreply.github.com>
@mattn
Copy link
Collaborator Author

mattn commented May 16, 2023

fixed tests

@fiatjaf
Copy link
Owner

fiatjaf commented May 17, 2023

Ready to merge?

@mattn
Copy link
Collaborator Author

mattn commented May 17, 2023

yes.

@fiatjaf fiatjaf merged commit 639c210 into fiatjaf:master May 17, 2023
}

ws.WriteJSON([]interface{}{"COUNT", id, map[string]int64{"count": total}})
setListener(id, ws, filters)

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.

Copy link
Collaborator Author

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?

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?

Copy link
Collaborator Author

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. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants