Skip to content

Commit

Permalink
Merge pull request ManageIQ#15191 from lpichler/memoize_root_tenant
Browse files Browse the repository at this point in the history
Memoize root tenant
  • Loading branch information
gtanzillo authored Jun 1, 2017
2 parents 9bbead5 + 0ea303b commit 8a0fa8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def self.default_tenant
#
# @return [Tenant] the root tenant
def self.root_tenant
@root_tenant ||= root_tenant_without_cache
end

def self.root_tenant_without_cache
in_my_region.roots.first
end

Expand Down Expand Up @@ -303,7 +307,7 @@ def nil_blanks
# validates that there is only one tree
def validate_only_one_root
unless parent_id || parent
root = self.class.root_tenant
root = self.class.root_tenant_without_cache
errors.add(:parent, "required") if root && root != self
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/support/evm_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def self.clear_caches
clear_instance_variable(MiqProductFeature, :@feature_cache) if defined?(MiqProductFeature)
clear_instance_variable(MiqProductFeature, :@obj_cache) if defined?(MiqProductFeature)
clear_instance_variable(BottleneckEvent, :@event_definitions) if defined?(BottleneckEvent)
clear_instance_variable(Tenant, :@root_tenant) if defined?(Tenant)

# Clear the thread local variable to prevent test contamination
User.current_user = nil if defined?(User) && User.respond_to?(:current_user=)
Expand Down

0 comments on commit 8a0fa8e

Please sign in to comment.