我在 Phusion Passenger、Nginx 和 Postgres 9.1.4 上运行 Rails 3.2 应用程序。按照本文中描述的方法,我已将多租户应用程序移至Postgresql 的模式(正在开发中):
由于这种方法似乎为每个请求全局设置模式搜索路径(通过 handle_subdomain,见下文),这如何影响后台作业(通过 Resque)?
class ApplicationController < ActionController::Base
before_filter :handle_subdomain
def handle_subdomain
if @tenant = Tenant.find_by_subdomain(request.subdomain)
PgTools.set_search_path @tenant.id
else
PgTools.restore_default_search_path
end
end
end
如果我随后在需要大量时间的 Resque 后台作业中设置搜索路径(例如,删除一堆托管在 S3 上的回形针图像),会发生什么情况?这是否可能会干扰对应用程序的请求,该请求在 handle_subdomain 中设置路径?
我应该修补 ActiveRecord 以硬编码模式搜索路径吗?EG select * from "1"."users" ("1" 是模式路径)
感谢您的任何帮助。