开发者

Rails - how can I query the db w/o touching the sessions table

开发者 https://www.devze.com 2022-12-30 07:28 出处:网络
I\'m trying to provide a HTTP api to my app that queries a db that\'s read-only (for replication purposes). I find that my app crashes re开发者_JS百科peatedly when making a request b/c the call is try

I'm trying to provide a HTTP api to my app that queries a db that's read-only (for replication purposes). I find that my app crashes re开发者_JS百科peatedly when making a request b/c the call is trying to update the sessions table whenever I query the db. This doesn't happen when I return some text without hitting the database for info.

class APIController < AplicationController

  def view
    data = Product.find(params[:id]).to_json # will fail
    data = { :one => 1, :two => 2 }.to_json  # will succeed

    respond_to do |format|
      format.html { render :json => data }
    end
  end  

end

How do I restrict it from touching the sessions table on this request (it's currently issuing an UPDATE on the updated_at field for that session). thanks.


What version of Rails is this? In Rails 2.3, sessions are lazy-loaded, so check in ApplicationController and your plugins for any code (probably in a before_filter) that is accessing any value in your session. You want to avoid that filter for this view action.


Are you using the session in this request? eg for authentication. That might be a problem.

You can disable the session for controller and/or action:

class MyController < ApplicationController
  session :off, :only => :view

  ...

end

Works a lot like the regular controller filters.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号