Permalink
Browse files

Update lib/middleware/session.js

Saving needed only when session changes, otherwise session do save on any page load (why if its not changed?). 
I think setTimeout can be replaced. 

Sorry for my bad english ;)
  • Loading branch information...
1 parent 3a3799c commit e2142b7245076ce3089093c599fcc3288faff02f @thomascoding thomascoding committed Oct 14, 2012
Showing with 13 additions and 7 deletions.
  1. +13 −7 lib/middleware/session.js
@@ -1,4 +1,3 @@
-
/*!
* Connect - session
* Copyright(c) 2010 Sencha Inc.
@@ -276,12 +275,19 @@ function session(options){
res.end = function(data, encoding){
res.end = end;
if (!req.session) return res.end(data, encoding);
- debug('saving');
- req.session.resetMaxAge();
- req.session.save(function(){
- debug('saved');
- res.end(data, encoding);
- });
+ if (originalHash == hash(req.session)) {
+ debug('unmodified session, dont save');
+ setTimeout(function(){
+ res.end(data, encoding);
+ },0);
+ }else{
+ debug('saving');
+ req.session.resetMaxAge();
+ req.session.save(function(){
+ debug('save session');
+ res.end(data, encoding);
+ });
+ }
};
// generate the session

0 comments on commit e2142b7

Please sign in to comment.