Secbone / koa-session2

Middleware for Koa2 to get/set session
MIT License
153 stars 30 forks source link

Remove excess session update #51

Closed mahovich closed 5 years ago

mahovich commented 5 years ago

When you add or update the contents of the session, there is an unnecessary update of the session, for example:

ctx.session.view = 'index_update';
ctx.session.new = 'new_param';

will create an http request with a cookie update (session).

In my opinion - this is a mistake, because session update should be performed only when calling ctx.session.refresh().

The current session behavior causes a lot of unnecessary session updates for any request to the engine, if, for example, with each request, it changes values ​​such as ctx.session.last_requests orctx.session.count_views_page.

Secbone commented 5 years ago

@mahovich thanks for your issue, and that's a pretty good idea. But I can not agree that the update action should be only when calling refresh. I think it should be automatic when the session is changed.

so I think the cookie should be updated only when the session id is changed. It seems smarter than now. What do you think? 😄

mahovich commented 5 years ago

I forgot about changing the session identifier - I did not use it on my projects... I'll make a change now.

And one more question:

the cookie should be updated only when the session id is changed

refresh() after all remains? You do not want to give it up?

Secbone commented 5 years ago

@mahovich It looks great! Thanks for your contribution, I will merge it. 😄