mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
Leverage Rails' caching when checking for admin
The privileges of a user should never change within a request life cycle. The `spree_roles` association is very small, between 0 and 2 items are quickly searched in memory without the need of additional database queries. From memory, I've seen a lot of spree_roles queries in log files per request. This should reduce it to one.
This commit is contained in:
@@ -60,7 +60,7 @@ module Spree
|
||||
|
||||
# Checks whether the specified user is a superadmin, with full control of the instance
|
||||
def admin?
|
||||
spree_roles.where(name: "admin").any?
|
||||
spree_roles.any? { |role| role.name == "admin" }
|
||||
end
|
||||
|
||||
# Send devise-based user emails asyncronously via ActiveJob
|
||||
|
||||
@@ -148,7 +148,6 @@ module Admin
|
||||
order_cycles: 6,
|
||||
proxy_orders: 1,
|
||||
schedules: 1,
|
||||
spree_roles: 9,
|
||||
spree_variants: 8,
|
||||
tags: 1
|
||||
},
|
||||
|
||||
@@ -140,8 +140,6 @@ RSpec.describe Reporting::Reports::OrdersAndDistributors::Base do
|
||||
subject # build context first
|
||||
|
||||
expect { subject.table_rows }.to query_database [
|
||||
"Spree::Role Exists?",
|
||||
"Spree::Role Exists?",
|
||||
"SQL",
|
||||
"Spree::LineItem Load",
|
||||
"Spree::PaymentMethod Load",
|
||||
|
||||
Reference in New Issue
Block a user