Rails:正在开发用于调优的 SQL_NO_CACHE

Jan*_*Jan 5 activerecord ruby-on-rails mysql2

让活动记录在开发环境中的所有查询中使用 SQL_NO_CACHE 的简单方法是什么?

我想针对最坏情况的加载时间优化语句。希望这样做是有意义的,但是我在第一页点击时得到的查询非常慢,而下一次所有查询都非常快,因为服务器应该缓存它们。

我正在使用 mysql2 gem 0.3.11 和 Rails 3.2.3。

Jan*_*Jan 2

由于我不想编辑数百个查询,因此我在应用程序控制器中放置了一个 before 过滤器,如下所示:

def disable_sql_query_cache_in_development
  if Rails.env == "development"
    Rails.logger.warn Utils.yellow "ApplicationController.disable_sql_query_cache_in_development", "Query cache will be reset for worst case performance tuning"
    #ActiveRecord::Base.connection.execute("SET SESSION query_cache_type = OFF")
    ActiveRecord::Base.connection.execute("RESET QUERY CACHE")
  end
end
Run Code Online (Sandbox Code Playgroud)