Replace current_user.id with session_current_user_id (#4880) [deploy]
* Replace current_user.id with efficient_current_user_id in high-leverage areas * Update name of efficient_current_user_id * Replace user_signed_in? in pageviews * Remove unneeded ?
This commit is contained in:
parent
e79ad764bd
commit
36479f09c3
7 changed files with 19 additions and 19 deletions
|
|
@ -18,9 +18,10 @@ class ApplicationController < ActionController::Base
|
|||
raise NotAuthorizedError, "Unauthorized"
|
||||
end
|
||||
|
||||
def efficient_current_user_id
|
||||
def session_current_user_id
|
||||
session["warden.user.user.key"].flatten[0] if session["warden.user.user.key"].present?
|
||||
end
|
||||
helper_method :session_current_user_id
|
||||
|
||||
def authenticate_user!
|
||||
return if current_user
|
||||
|
|
|
|||
|
|
@ -110,9 +110,8 @@ class ChatChannelsController < ApplicationController
|
|||
end
|
||||
|
||||
def render_unopened_json_response
|
||||
@chat_channels_memberships = if current_user
|
||||
current_user.
|
||||
chat_channel_memberships.includes(:chat_channel).
|
||||
@chat_channels_memberships = if session_current_user_id
|
||||
ChatChannelMembership.where(user_id: session_current_user_id).includes(:chat_channel).
|
||||
where("has_unopened_messages = ? OR status = ?",
|
||||
true, "pending").
|
||||
where(show_global_badge_notification: true).
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class DisplayAdEventsController < ApplicationController
|
|||
# No policy needed. All views are for all users
|
||||
def create
|
||||
# Only tracking for logged in users at the moment
|
||||
display_ad_event_create_params = display_ad_event_params.merge(user_id: current_user.id)
|
||||
display_ad_event_create_params = display_ad_event_params.merge(user_id: session_current_user_id)
|
||||
@display_ad_event = DisplayAdEvent.create(display_ad_event_create_params)
|
||||
|
||||
update_display_ads_data
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class MessagesController < ApplicationController
|
|||
|
||||
def create
|
||||
@message = Message.new(message_params)
|
||||
@message.user_id = current_user.id
|
||||
@message.user_id = session_current_user_id
|
||||
authorize @message
|
||||
success = false
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
class PageViewsController < ApplicationController
|
||||
# No policy needed. All views are for all users
|
||||
def create
|
||||
page_view_create_params = if user_signed_in?
|
||||
page_view_params.merge(user_id: current_user.id)
|
||||
page_view_create_params = if session_current_user_id
|
||||
page_view_params.merge(user_id: session_current_user_id)
|
||||
else
|
||||
page_view_params.merge(counts_for_number_of_views: 10)
|
||||
end
|
||||
|
|
@ -15,10 +15,10 @@ class PageViewsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
if user_signed_in?
|
||||
page_view = PageView.where(article_id: params[:id], user_id: current_user.id).last
|
||||
if session_current_user_id
|
||||
page_view = PageView.where(article_id: params[:id], user_id: session_current_user_id).last
|
||||
# pageview is sometimes missing if failure on prior creation.
|
||||
page_view ||= PageView.create(user_id: current_user.id, article_id: params[:id])
|
||||
page_view ||= PageView.create(user_id: session_current_user_id, article_id: params[:id])
|
||||
page_view.update_column(:time_tracked_in_seconds, page_view.time_tracked_in_seconds + 15)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ class ReactionsController < ApplicationController
|
|||
skip_authorization
|
||||
if params[:article_id]
|
||||
id = params[:article_id]
|
||||
reactions = if efficient_current_user_id.present?
|
||||
reactions = if session_current_user_id.present?
|
||||
Reaction.where(reactable_id: id,
|
||||
reactable_type: "Article",
|
||||
user_id: efficient_current_user_id).
|
||||
user_id: session_current_user_id).
|
||||
where("points > ?", 0)
|
||||
else
|
||||
[]
|
||||
end
|
||||
render json:
|
||||
{
|
||||
current_user: { id: efficient_current_user_id },
|
||||
current_user: { id: session_current_user_id },
|
||||
article_reaction_counts: Reaction.count_for_article(id),
|
||||
reactions: reactions
|
||||
}.to_json
|
||||
|
|
@ -27,15 +27,15 @@ class ReactionsController < ApplicationController
|
|||
).select(%i[id positive_reactions_count])
|
||||
comment_ids = comments.map(&:id)
|
||||
reaction_counts = comments.map { |c| { id: c.id, count: c.positive_reactions_count } }
|
||||
reactions = current_user ? cached_user_positive_reactions(current_user).where(reactable_id: comment_ids) : []
|
||||
reactions = session_current_user_id ? cached_user_positive_reactions(current_user).where(reactable_id: comment_ids) : []
|
||||
render json:
|
||||
{
|
||||
current_user: { id: current_user&.id },
|
||||
current_user: { id: session_current_user_id },
|
||||
positive_reaction_counts: reaction_counts,
|
||||
reactions: reactions
|
||||
}.to_json
|
||||
end
|
||||
set_surrogate_key_header params.to_s unless current_user
|
||||
set_surrogate_key_header params.to_s unless session_current_user_id
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class ReadingListItemsController < ApplicationController
|
|||
|
||||
def update
|
||||
@reaction = Reaction.find(params[:id])
|
||||
raise if @reaction.user_id != current_user.id # Lazy but I'm tired. HACK
|
||||
raise if @reaction.user_id != session_current_user_id # Lazy but I'm tired. HACK
|
||||
|
||||
@reaction.status = params[:current_status] == "archived" ? "valid" : "archived"
|
||||
@reaction.save
|
||||
|
|
@ -17,7 +17,7 @@ class ReadingListItemsController < ApplicationController
|
|||
private
|
||||
|
||||
def generate_algolia_search_key
|
||||
params = { filters: "viewable_by:#{current_user.id}" }
|
||||
params = { filters: "viewable_by:#{session_current_user_id}" }
|
||||
@secured_algolia_key = Algolia.generate_secured_api_key(
|
||||
ApplicationConfig["ALGOLIASEARCH_SEARCH_ONLY_KEY"], params
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue