1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 PERMISSION_VIEW = "materialized_permission_view"
7 def do_refresh_permission_view
8 ActiveRecord::Base.transaction do
9 ActiveRecord::Base.connection.execute("LOCK TABLE permission_refresh_lock")
10 ActiveRecord::Base.connection.execute("REFRESH MATERIALIZED VIEW #{PERMISSION_VIEW}")
14 def refresh_permission_view(async=false)
15 if async and Rails.configuration.API.AsyncPermissionsUpdateInterval > 0
16 exp = Rails.configuration.API.AsyncPermissionsUpdateInterval.seconds
18 Rails.cache.fetch('AsyncRefreshPermissionView', expires_in: exp) do
22 # Schedule a new permission update and return immediately
24 Thread.current.abort_on_exception = false
27 Rails.cache.delete('AsyncRefreshPermissionView')
28 do_refresh_permission_view
30 Rails.logger.error "Updating permission view: #{e}\n#{e.backtrace.join("\n\t")}"
32 ActiveRecord::Base.connection.close
38 do_refresh_permission_view