1

我在 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" 是模式路径)

感谢您的任何帮助。

4

1 回答 1

1

如果 ActiveRecord 只是发出“SET search_path = x”命令,那么这就是设置每个会话的值,所以你应该没问题。

事实上,如果您在显式事务中设置它,如果事务回滚*,它将在事务结束时回滚*。

  • 澄清以下来自 araqnid 的评论
于 2012-08-20T08:13:51.203 回答