OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Improve performance of /api/v3/capabilities endpoint
Christophe Bliardfc5b44a80330
diff --git a/app/models/actions/scopes/default.rb b/app/models/actions/scopes/default.rbindex 070f4ded3c2..13c5ac4728c 100644--- a/app/models/actions/scopes/default.rb+++ b/app/models/actions/scopes/default.rb@@ -32,13 +32,16 @@ module Actions::Scopesclass_methods dodef default- actions_sql = <<~SQL.squish- (SELECT id, permission, global, module, grant_to_admin- FROM (VALUES #{action_map}) AS t(id, permission, global, module, grant_to_admin)) actions- SQL+ RequestStore[:action_default_scope] ||= begin+ actions_sql = <<~SQL.squish+ (SELECT id, permission, global, module, grant_to_admin+ FROM (VALUES #{action_map}) AS t(id, permission, global, module, grant_to_admin)) actions+ SQL- select('actions.*')- .from(actions_sql)+ unscoped # prevent triggering the default scope again+ .select('actions.*')+ .from(actions_sql)+ endendprivatediff --git a/app/models/capabilities/scopes/default.rb b/app/models/capabilities/scopes/default.rbindex 7d0a07a5735..83701b52888 100644--- a/app/models/capabilities/scopes/default.rb+++ b/app/models/capabilities/scopes/default.rb@@ -46,14 +46,15 @@ module Capabilities::Scopes) capabilitiesSQL- select('capabilities.*')+ unscoped # prevent triggering the default scope again+ .select('capabilities.*').from(capabilities_sql)endprivatedef default_sql_by_member- <<~SQL.squish+ <<~SQL_PARTSELECT DISTINCTactions.id "action",users.id principal_id,@@ -72,11 +73,11 @@ module Capabilities::ScopesAND actions.module = enabled_modules.nameWHERE (projects.active AND (enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL))OR (projects.id IS NULL AND "actions".global)- SQL+ SQL_PARTenddef default_sql_by_admin- <<~SQL.squish+ <<~SQL_PARTSELECT DISTINCTactions.id "action",users.id principal_id,@@ -91,11 +92,11 @@ module Capabilities::ScopesON enabled_modules.project_id = projects.idAND actions.module = enabled_modules.nameWHERE (projects.id IS NOT NULL AND (enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL)) OR "actions".global- SQL+ SQL_PARTenddef default_sql_by_non_member- <<~SQL.squish+ <<~SQL_PARTSELECT DISTINCTactions.id "action",users.id principal_id,@@ -117,11 +118,11 @@ module Capabilities::ScopesAND actions.module = enabled_modules.nameWHERE enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL- SQL+ SQL_PARTenddef default_sql_by_non_member_with_anonymous- <<~SQL.squish+ <<~SQL_PARTSELECT DISTINCTactions.id "action",users.id principal_id,@@ -138,7 +139,7 @@ module Capabilities::ScopesAND actions.module = enabled_modules.nameWHERE enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL- SQL+ SQL_PARTendendend