Skip to content

Commit

Permalink
Properly delete expired sessions.
Browse files Browse the repository at this point in the history
Also use bulk delete instead of many queries.  Resolves opengovfoundation/madison-editor#3
  • Loading branch information
Bill Hunt committed Aug 28, 2015
1 parent eef5656 commit 51885bb
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/connect-mysql-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,11 @@ module.exports = function (connect)
{
if (error) return;

Session.findAll({where: ['last_activity < ?', Math.round(Date.now() / 1000) + defaultExpiration]})
.on('success', function (sessions)
{
if (sessions.length > 0)
{
//console.log('Destroying ' + sessions.length + ' expired sessions.');
for (var i in sessions)
{
sessions[i].destroy();
}
}
})
Session.destroy({'last_activity': {'lt': Math.round(Date.now() / 1000) - defaultExpiration}})
// .on('success', function (sessions)
// {
// console.log('success');
// })
.on('failure', function (error)
{
console.log('Failed to fetch expired sessions:');
Expand Down

0 comments on commit 51885bb

Please sign in to comment.