Skip to content

Commit ac5befb

Browse files
committed
Fix memoization for current_user and current_contributor
Previously, if no user was found, we might have queried the same method multiple times (since nil is not present).
1 parent 3b7b418 commit ac5befb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

app/controllers/application_controller.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ class ApplicationController < ActionController::Base
2525
add_flash_types :danger, :warning, :info, :success
2626

2727
def current_user
28-
@current_user ||= find_or_login_current_user&.store_current_study_group_id(session[:study_group_id])
28+
return @current_user if defined? @current_user
29+
30+
@current_user = find_or_login_current_user&.store_current_study_group_id(session[:study_group_id])
2931
end
3032

3133
def current_contributor
32-
@current_contributor ||= if session[:pg_id]
33-
current_user.programming_groups.find(session[:pg_id])
34-
else
35-
current_user
36-
end
34+
return @current_contributor if defined? @current_contributor
35+
36+
@current_contributor = if session[:pg_id]
37+
current_user.programming_groups.find(session[:pg_id])
38+
else
39+
current_user
40+
end
3741
end
3842
helper_method :current_contributor
3943

0 commit comments

Comments
 (0)