More efficient query for watched_by? and use etag for the status

This commit is contained in:
David Heinemeier Hansson
2025-11-03 16:51:19 +01:00
parent f5977522cb
commit 418548b9ba
2 changed files with 9 additions and 1 deletions
@@ -1,6 +1,10 @@
class Cards::WatchesController < ApplicationController
include CardScoped
def show
fresh_when etag: @card.watch_for(Current.user)
end
def create
@card.watch_by Current.user
end
+5 -1
View File
@@ -9,7 +9,11 @@ module Card::Watchable
end
def watched_by?(user)
watchers.include?(user)
watch_for(user)&.watching?
end
def watch_for(user)
watches.find_by(user: user)
end
def watch_by(user)