From fa994c9c9b8eaeaf52abce4504c6a7df18ac35c6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 24 Nov 2015 14:05:35 +0100 Subject: [PATCH] Revert "v3: in access control object, avoid firing multiple permissions queries (even though they are cache hits)" This reverts commit 4a3357a4888b424a1074d2f3c10df951467e185a. --- lib/travis/api/v3/access_control/user.rb | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/travis/api/v3/access_control/user.rb b/lib/travis/api/v3/access_control/user.rb index 5b6460fe..e48bb577 100644 --- a/lib/travis/api/v3/access_control/user.rb +++ b/lib/travis/api/v3/access_control/user.rb @@ -8,7 +8,6 @@ module Travis::API::V3 user = Models::User.find(user.id) if user.is_a? ::User @user = user @access_permissions = user.permissions.where(user_id: user.id) - @got_request = false super() end @@ -21,7 +20,6 @@ module Travis::API::V3 end def visible_repositories(list) - load_permissions list.where('repositories.private = false OR repositories.id IN (?)'.freeze, access_permissions.map(&:repository_id)) end @@ -49,19 +47,7 @@ module Travis::API::V3 def permission?(type, id) id = id.id if id.is_a? ::Repository - - load_permissions if @got_request - @got_request = true - - if access_permissions.respond_to? :where - access_permissions.where(type => true, :repository_id => id).any? - else - access_permissions.any? { |p| p[type] == true and p.repository_id == id } - end - end - - def load_permissions - @access_permissions = @access_permissions.to_a + access_permissions.where(type => true, :repository_id => id).any? end end end