Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

class Comment < ApplicationRecord
validates :author, :text, presence: true
after_commit { CommentRelayJob.perform_later(self) }
after_create_commit { CommentRelayJob.perform_later(self) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Broadcasting silently dropped for updates and destroys

after_create_commit only fires after an INSERT, so comment edits and deletes no longer enqueue CommentRelayJob. The app exposes both update and destroy actions via CommentsController, so any client subscribed to the "comments" ActionCable channel will continue to see stale data after a comment is edited or deleted. If real-time updates on create are the only required behaviour this is fine, but the PR description frames it purely as a performance improvement, which obscures the functional trade-off.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we want to see updates for edits as well.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Then this change introduces a regression. You should revert to after_commit (which fires on create, update, and destroy), or be explicit about the callbacks you want:

Suggested change
after_create_commit { CommentRelayJob.perform_later(self) }
after_create_commit { CommentRelayJob.perform_later(self) }
after_update_commit { CommentRelayJob.perform_later(self) }

Or more concisely, just keep the original:

after_commit { CommentRelayJob.perform_later(self) }

The original code was correct. The PR description's claim that after_create_commit is a "performance improvement" is only true if you intentionally want to drop update/delete relaying — which you don't. This PR should not be merged as-is.

end