mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Improve permissions query building
For larger queries and especially where filtering and paginating, these simpler product queries are way more efficient. It cuts out some very large subqueries with large lists of product ids.
This commit is contained in:
@@ -60,21 +60,23 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def editable_products
|
||||
permitted_enterprise_products_ids = product_ids_supplied_by(
|
||||
related_enterprises_granting(:manage_products)
|
||||
)
|
||||
Spree::Product.where(
|
||||
id: managed_enterprise_products.select(:id) | permitted_enterprise_products_ids
|
||||
return Spree::Product.all if admin?
|
||||
|
||||
Spree::Product.where(supplier_id: @user.enterprises).or(
|
||||
Spree::Product.where(supplier_id: related_enterprises_granting(:manage_products))
|
||||
)
|
||||
end
|
||||
|
||||
def visible_products
|
||||
permitted_enterprise_products_ids = product_ids_supplied_by(
|
||||
related_enterprises_granting(:manage_products) |
|
||||
related_enterprises_granting(:add_to_order_cycle)
|
||||
)
|
||||
return Spree::Product.all if admin?
|
||||
|
||||
Spree::Product.where(
|
||||
id: managed_enterprise_products.select(:id) | permitted_enterprise_products_ids
|
||||
supplier_id: @user.enterprises
|
||||
).or(
|
||||
Spree::Product.where(
|
||||
supplier_id: related_enterprises_granting(:manage_products) |
|
||||
related_enterprises_granting(:add_to_order_cycle)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user