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

Note subscriptions db table #5284

Merged

Conversation

AntonKhorev
Copy link
Collaborator

Part one of #5283. Creates the note subscription table and starts adding subscriptions for anyone who comments a note. These subscriptions are not yet used for anything, email notifications still go to all note commenters.

@AntonKhorev AntonKhorev added api Related to the XML or JSON APIs javascript Pull requests that update Javascript code notes Related to the notes feature labels Oct 25, 2024
@@ -401,6 +401,8 @@ def add_comment(note, text, event, notify: true)
note.comments.map(&:author).uniq.each do |user|
UserMailer.note_comment_notification(comment, user).deliver_later if notify && user && user != current_user && user.visible?
end

NoteSubscription.find_or_create_by(:note => note, :user => current_user) if current_user
Copy link
Member

Choose a reason for hiding this comment

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

I think this could be simplified using the association?

Suggested change
NoteSubscription.find_or_create_by(:note => note, :user => current_user) if current_user
current_user&.note__subscriptions.find_or_create_by(:note => note)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would require one more &. after note__subscriptions, so it depends on whether you think that chained &.s are simplifications.

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe it does - if current_user is defined then the note_subscriptions association will always exist. It might evaluate to an empty list but the association object will exist and can have methods invoked on 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.

Try running Rubocop.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm you're quite right, and rubocop is quite right, which I find quite odd but apparently ruby does continue evaluating the line after the first &. fails.

Personally I still think I prefer it but it's not a huge issue.

assert_equal user.display_name, js["properties"]["comments"].last["user"]

note = Note.last
subscription = NoteSubscription.last
Copy link
Member

Choose a reason for hiding this comment

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

This (and all the other similar versions in other tests) is relying on nothing else having created notes or users in a way that overlaps this test and I'm not sure how safe that is when tests are running in parallel?

Maybe it would be better to get the node ID from the JSON response and then do assert Note.exists?(id) and a similar exists assertion on the subscription record?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how safe that is when tests are running in parallel?

Parallel tests are run in separate databases (e.g. openstreetmap_test-0 etc)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This ... is relying on nothing else having created notes

There is a check assert_difference "Note.count", 1

(and all the other similar versions in other tests)

Other tests in this file or other tests elsewhere? You can find similar uses of .last from years ago.

@AntonKhorev AntonKhorev force-pushed the note-subscriptions-db-table branch from 954e7b3 to 2d7e0a3 Compare October 27, 2024 23:37
@tomhughes
Copy link
Member

It looks like there are no significant issues here, so I'll merge this. Thanks for the work.

@tomhughes tomhughes merged commit dbb462c into openstreetmap:master Oct 31, 2024
22 checks passed
@AntonKhorev AntonKhorev deleted the note-subscriptions-db-table branch November 6, 2024 09:50
@AntonKhorev AntonKhorev mentioned this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the XML or JSON APIs javascript Pull requests that update Javascript code notes Related to the notes feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants