Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From e80252e48de52485e5d1a68f0cea2e7420326abe Mon Sep 17 00:00:00 2001
From: Matthijs Langenberg <mlangenberg@gmail.com>
Date: Mon, 24 Jan 2011 11:37:14 +0100
Subject: [PATCH] Prevent ActiveRecord SessionStore from saving non-dirty sessions.
---
activerecord/lib/active_record/session_store.rb | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb
index 3400fd6..425dd2e 100644
--- a/activerecord/lib/active_record/session_store.rb
+++ b/activerecord/lib/active_record/session_store.rb
@@ -81,6 +81,7 @@ module ActiveRecord
cattr_accessor :data_column_name
self.data_column_name = 'data'
+ before_save :data_changed?
before_save :marshal_data!
before_save :raise_on_session_data_overflow!
@@ -139,6 +140,17 @@ module ActiveRecord
end
private
+ def original_data
+ if changes && changes[@@data_column_name] && changes[@@data_column_name][0]
+ return self.class.unmarshal(changes[@@data_column_name][0])
+ end
+ return {}
+ end
+
+ def data_changed?
+ return false if original_data == data
+ end
+
def marshal_data!
return false unless loaded?
write_attribute(@@data_column_name, self.class.marshal(data))
--
1.6.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment