tweak region scope

refs CNVS-15955

add a scope for specifying the region

Change-Id: I9709e2d47c241115ed9a868ba1660d34e92f126b
Reviewed-on: https://gerrit.instructure.com/42101
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2014-10-01 11:59:14 -06:00
parent 5e7de1578b
commit 65f7e2a03e
1 changed files with 11 additions and 7 deletions

View File

@ -90,17 +90,21 @@ Rails.application.config.to_prepare do
delegate :in_current_region?, to: :database_server
scope :in_region, ->(region) do
servers = DatabaseServer.all.select { |db| db.config[:region] == region }.map(&:id)
if Shard.default.database_server.config[:region] == region
where("database_server_id IN (?) OR database_server_id IS NULL", servers)
else
where(database_server_id: servers)
end
end
scope :in_current_region, -> do
@scope ||=
@current_region_scope ||=
if !ApplicationController.region || DatabaseServer.all.all? { |db| !db.config[:region] }
scoped
else
servers = DatabaseServer.all.select(&:in_current_region?).map(&:id)
if Shard.default.database_server.in_current_region?
where("database_server_id IN (?) OR database_server_id IS NULL", servers)
else
where(database_server_id: servers)
end
in_region(ApplicationController.region)
end
end
end