16007: Make sure trash table gets refreshed on database reset
authorPeter Amstutz <peter.amstutz@curii.com>
Thu, 14 May 2020 21:08:48 +0000 (17:08 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Thu, 14 May 2020 21:08:48 +0000 (17:08 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

services/api/app/controllers/database_controller.rb
services/api/app/models/arvados_model.rb
services/api/app/models/database_seeds.rb
services/api/lib/refresh_permission_view.rb
services/api/test/performance/permission_test.rb
services/api/test/test_helper.rb

index d6045a5dcbf35a3c786bb6db5105d49e9636cc39..24c6cf5a790b887fbad41eaefecfe2910d36424c 100644 (file)
@@ -78,6 +78,7 @@ class DatabaseController < ApplicationController
     require 'refresh_permission_view'
 
     refresh_permission_view
+    refresh_trashed
 
     # Done.
     send_json success: true
index 00f9254b2e682c85df1a78a15449074256653ba8..e168cc608efe2fd9b9eae8c7dfa1d42660c32b9a 100644 (file)
@@ -296,14 +296,14 @@ class ArvadosModel < ApplicationRecord
       if !include_trash
         if sql_table != "api_client_authorizations"
           # Only include records where the owner is not trashed
-          sql_conds = "#{sql_table}.owner_uuid NOT IN (SELECT group_uuid FROM trashed_groups "+
+          sql_conds = "#{sql_table}.owner_uuid NOT IN (SELECT group_uuid FROM #{TRASHED_GROUPS} "+
                       "where trash_at <= statement_timestamp()) #{exclude_trashed_records}"
         end
       end
     else
       trashed_check = ""
       if !include_trash then
-        trashed_check = "AND target_uuid NOT IN (SELECT group_uuid FROM trashed_groups where trash_at <= statement_timestamp())"
+        trashed_check = "AND target_uuid NOT IN (SELECT group_uuid FROM #{TRASHED_GROUPS} where trash_at <= statement_timestamp())"
       end
 
       # Note: it is possible to combine the direct_check and
index d546a0466be3e16af89d684409128f768ed33520..0fea2cf7b609e5e4fccc929e6935668d03875723 100644 (file)
@@ -14,6 +14,7 @@ class DatabaseSeeds
     anonymous_group_read_permission
     anonymous_user
     empty_collection
-    do_refresh_permission_view
+    refresh_permission_view
+    refresh_trashed
   end
 end
index 77235c00069942500ac7efbafc5cd954290c7618..c00ceaf99a138b82c08e7e7d4ea9a05dce971284 100644 (file)
@@ -5,7 +5,7 @@
 PERMISSION_VIEW = "materialized_permissions"
 TRASHED_GROUPS = "trashed_groups"
 
-def do_refresh_permission_view
+def refresh_permission_view
   ActiveRecord::Base.transaction do
     ActiveRecord::Base.connection.execute("LOCK TABLE #{PERMISSION_VIEW}")
     ActiveRecord::Base.connection.execute("DELETE FROM #{PERMISSION_VIEW}")
@@ -18,35 +18,11 @@ from users, lateral search_permission_graph(users.uuid, 3) as g where g.val > 0
   end
 end
 
-def refresh_permission_view(async=false)
-  if async and Rails.configuration.API.AsyncPermissionsUpdateInterval > 0
-    exp = Rails.configuration.API.AsyncPermissionsUpdateInterval.seconds
-    need = false
-    Rails.cache.fetch('AsyncRefreshPermissionView', expires_in: exp) do
-      need = true
-    end
-    if need
-      # Schedule a new permission update and return immediately
-      Thread.new do
-        Thread.current.abort_on_exception = false
-        begin
-          sleep(exp)
-          Rails.cache.delete('AsyncRefreshPermissionView')
-          do_refresh_permission_view
-        rescue => e
-          Rails.logger.error "Updating permission view: #{e}\n#{e.backtrace.join("\n\t")}"
-        ensure
-          ActiveRecord::Base.connection.close
-        end
-      end
-      true
-    end
-  else
-    do_refresh_permission_view
-  end
+def refresh_trashed
+  ActiveRecord::Base.connection.execute("DELETE FROM #{TRASHED_GROUPS}")
+  ActiveRecord::Base.connection.execute("INSERT INTO #{TRASHED_GROUPS} select * from compute_trashed()")
 end
 
-
 def update_permissions perm_origin_uuid, starting_uuid, perm_level, check=true
   # Update a subset of the permission graph
   # perm_level is the inherited permission
index 81edf488a78c543fe651b6eec53a16a761590392..0fea3b13503278f80c82d8713a60ce4ef1ee4971 100644 (file)
@@ -40,8 +40,7 @@ class PermissionPerfTest < ActionDispatch::IntegrationTest
                    end
                  end
                end
-               #User.invalidate_permissions_cache
-               do_refresh_permission_view
+               refresh_permission_view
              end
            end)
     end
index c6ea0b320fdac3a0183c15ae1d37603cf4ef9e8e..12f729e3384ac9b81107b744c6a52873c24fe3ea 100644 (file)
@@ -209,6 +209,5 @@ class ActionDispatch::IntegrationTest
 end
 
 # Ensure permissions are computed from the test fixtures.
-do_refresh_permission_view
-ActiveRecord::Base.connection.execute("DELETE FROM #{TRASHED_GROUPS}")
-ActiveRecord::Base.connection.execute("INSERT INTO #{TRASHED_GROUPS} select * from compute_trashed()")
+refresh_permission_view
+refresh_trashed