Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-09-10 03:05:55 +0300
committerStan Hu <stanhu@gmail.com>2019-09-10 07:51:57 +0300
commit08c3e59aeed34ad71e74afb674ddda7327fdc3a7 (patch)
tree544d9fa244519ac8b18b29ff8abf47bfdd40b30a /app/models/oauth_access_token.rb
parentffa5328c39f195d3253e586569fc2474d3aa6860 (diff)
Optimize /admin/applications so that it does not timeout
On our dev instance, /admin/applications as not loading because: 1. There was an unindexed query by `application_id`. 2. There was an expensive query that attempted to load 1 million unique entries via ActiveRecord just to find the unique count. We fix the first issue by adding an index for that column. We fix the second issue with a simple SELECT COUNT(DISTINCT resource_owner_id) SQL query. In addition, we add pagination to avoid loading more than 20 applications at once. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/67228
Diffstat (limited to 'app/models/oauth_access_token.rb')
-rw-r--r--app/models/oauth_access_token.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/app/models/oauth_access_token.rb b/app/models/oauth_access_token.rb
index 0aa920fa828..9789d8ed62b 100644
--- a/app/models/oauth_access_token.rb
+++ b/app/models/oauth_access_token.rb
@@ -6,6 +6,8 @@ class OauthAccessToken < Doorkeeper::AccessToken
alias_attribute :user, :resource_owner
+ scope :distinct_resource_owner_counts, ->(applications) { where(application: applications).distinct.group(:application_id).count(:resource_owner_id) }
+
def scopes=(value)
if value.is_a?(Array)
super(Doorkeeper::OAuth::Scopes.from_array(value).to_s)