users: drop id_to_name, name_to_id caching.
Changes: * Drop Users.id_to_name. * Don't cache Users.name_to_id. * Replace calls to name_to_id with find_by_name when possible. * Don't autodefine creator_name in belongs_to_creator. * Don't autodefine updater_name in belongs_to_updater. * Instead manually define creator_name / updater_name only on models that need to return these fields in the api. id_to_name was cached to reduce the impact of N+1 query patterns in certain places, especially in api responses that return creator_name / updater_name fields. But it still meant we were doing N calls to memcache. Using `includes` to prefetch users avoids this N+1 pattern. name_to_id had no need be cached, it was never used in any performance- sensitive contexts. Avoiding caching also avoids the need to keep these caches consistent.
This commit is contained in:
@@ -17,8 +17,8 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:title => ->(user_name) {"#{creator_name} mentioned you in a comment on post ##{post_id}"},
|
||||
:body => ->(user_name) {"@#{creator_name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n"},
|
||||
:title => ->(user_name) {"#{creator.name} mentioned you in a comment on post ##{post_id}"},
|
||||
:body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n"},
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
@@ -183,6 +183,14 @@ class Comment < ApplicationRecord
|
||||
super + [:creator_name, :updater_name]
|
||||
end
|
||||
|
||||
def creator_name
|
||||
creator.name
|
||||
end
|
||||
|
||||
def updater_name
|
||||
updater.name
|
||||
end
|
||||
|
||||
def delete!
|
||||
update(is_deleted: true)
|
||||
end
|
||||
@@ -192,6 +200,6 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
|
||||
def quoted_response
|
||||
DText.quote(body, creator_name)
|
||||
DText.quote(body, creator.name)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user