mweibel / connect-session-sequelize

Sequelize SessionStore for Express/Connect
212 stars 72 forks source link

Writing to database on every request #67

Closed crisward closed 6 years ago

crisward commented 6 years ago

This seems to write to the database on every request.

Could it have a threshold added, so it only updates the database every minute, or a user configurable period, based on the updated_at time?

mweibel commented 6 years ago

You're welcome to open a PR with the proposed change. What's the reason for this request?

crisward commented 6 years ago

I've been trying to optimise an application, the biggest bottleneck tends to be the database, so I've been looking to reduce the number of queries and updates. Selecting and updating the session time on every request seems excessive. On high traffic sites we use Redis, but it'd nice to be able to avoid the extra dependency if we can squeeze a bit more our of this module.

I'll see what I can do about a PR.

tony-gutierrez commented 6 years ago

I came here looking for this option as well. I don't need millisecond level expiration updates. It tends to do a lot of db writing.

mweibel commented 6 years ago

I welcome any PR 👍

tony-gutierrez commented 6 years ago

It looks like there are some problems with trying to solve this in this library.

You would basically have to do a read in order to know not to do an update, so that isnt going to really help.

This might be something that is better solved at the "connect" or "express-session" library level.

tony-gutierrez commented 6 years ago

I'm actually not sure why touch() is being called by "express-session" on every request? I cant seem to disable rolling updates in the "express-session" library.

tony-gutierrez commented 6 years ago

See here: https://github.com/expressjs/session/pull/531

tony-gutierrez commented 6 years ago

I think the best thing that could be done in this library is to offer an option that would basically disable the touch() method from doing anything. That way the user can force a save() on the session by updating its variables, and not worry about the db being written to every request.

tony-gutierrez commented 6 years ago

Added PR #70

mweibel commented 6 years ago

fixed in #70 Release coming soon

mweibel commented 6 years ago

released version 5.2.0 on npm.