general: only save session when there are changes (#22104)
This commit is contained in:
parent
d222855787
commit
a243987056
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import copy
|
||||
import os
|
||||
import time
|
||||
|
||||
|
@ -122,6 +123,25 @@ class Session(QommonSession, CaptchaSession, StorableObject):
|
|||
QuixoteSession.has_info(self)
|
||||
is_dirty = has_info
|
||||
|
||||
def migrate(self):
|
||||
# abuse migrate (as it is called after a session is loaded) to keep
|
||||
# track of original content, to avoid saving it when there's no change.
|
||||
self.__orig_dict__ = copy.deepcopy(self.__dict__)
|
||||
|
||||
def __getstate__(self):
|
||||
odict = copy.copy(self.__dict__)
|
||||
if '__orig_dict__' in odict:
|
||||
del odict['__orig_dict__']
|
||||
return odict
|
||||
|
||||
def store(self, *args, **kwargs):
|
||||
current_dict = copy.copy(self.__dict__)
|
||||
orig_dict = current_dict.pop('__orig_dict__', {})
|
||||
current_dict.pop('_access_time', None)
|
||||
orig_dict.pop('_access_time', None)
|
||||
if current_dict != orig_dict:
|
||||
return super(Session, self).store(*args, **kwargs)
|
||||
|
||||
def get_session_id(self):
|
||||
return self.id
|
||||
|
||||
|
|
Loading…
Reference in New Issue