Skip to content

Commit

Permalink
Using findCreateFind instead of using findOrCreate
Browse files Browse the repository at this point in the history
 `findOrCreate` does the select and insert (if necessary) in a transaction.
 For the purpose of sequelize store set, this is probably not required as
 updating the same session concurrently in more than one request might not be
 applicable.
 Using `findOrCreate` has shown a high memory usage and potentially crashing the DB
 under postgres, as sequelize uses temp functions setup transactions and trace any
 failures.
 This change is to use the more performant non-transactional `findCreateFind` function.
  • Loading branch information
imranbohoran committed Nov 1, 2016
1 parent 412d9d1 commit c18231b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/connect-session-sequelize.js
Expand Up @@ -84,7 +84,7 @@ module.exports = function SequelizeSessionInit (Store) {
defaults = this.options.extendDefaultFields(defaults, data)
}

return this.sessionModel.findOrCreate({where: {'sid': sid}, defaults: defaults}).spread(function sessionCreated (session) {
return this.sessionModel.findCreateFind({where: {'sid': sid}, defaults: defaults}).spread(function sessionCreated (session) {
var changed = false
Object.keys(defaults).forEach(function (key) {
if (key === 'data') {
Expand Down

0 comments on commit c18231b

Please sign in to comment.