Merge pull request #7860 from opf/fix/anonymous_user_in_request_store

memoize anonymous in request store

[ci skip]
pull/7871/head
Oliver Günther 5 years ago committed by GitHub
commit 969668a584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      app/models/user.rb

@ -678,18 +678,21 @@ class User < Principal
# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
# one anonymous user per database.
def self.anonymous
anonymous_user = AnonymousUser.first
if anonymous_user.nil?
(anonymous_user = AnonymousUser.new.tap do |u|
u.lastname = 'Anonymous'
u.login = ''
u.firstname = ''
u.mail = ''
u.status = 0
end).save
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
RequestStore[:anonymous_user] ||= begin
anonymous_user = AnonymousUser.first
if anonymous_user.nil?
(anonymous_user = AnonymousUser.new.tap do |u|
u.lastname = 'Anonymous'
u.login = ''
u.firstname = ''
u.mail = ''
u.status = 0
end).save
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
end
anonymous_user
end
anonymous_user
end
def self.system

Loading…
Cancel
Save