Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we're not memoizing the connection #9153

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/sessions/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ class ActiveRecord < ::ApplicationRecord
def readonly?
true
end

def data
SqlBypass.deserialize(super)
end
end
end
15 changes: 13 additions & 2 deletions app/models/sessions/sql_bypass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,28 @@ class << self
# @param session_id [String] The session ID as found in the `_open_project_session` cookie
# @return [Hash] The saved session data (user_id, updated_at, etc.) or nil if no session was found.
def lookup_data(session_id)
rack_session = Rack::Session::SessionId.new(session_id)
if Rails.application.config.session_store == ActionDispatch::Session::ActiveRecordStore
find_by_session_id(session_id)&.data
find_by_session_id(rack_session.private_id)&.data
else
session_store = Rails.application.config.session_store.new nil, {}
_id, data = session_store.instance_eval do
find_session({}, Rack::Session::SessionId.new(session_id))
find_session({}, rack_session)
end

data.presence
end
end

##
# Ensure we're not memoizing the connection
def connection
::ActiveRecord::Base.connection
end

def connection_pool
::ActiveRecord::Base.connection_pool
end
end

##
Expand Down