M
M
Maxim Uvarov2019-05-28 09:11:50
Laravel
Maxim Uvarov, 2019-05-28 09:11:50

Why does Laravel 5.8 make repeated database queries when working with a session?

In laravel 5.8, when working with a session, two extra database queries are performed compared to laravel 5.7.
5cecd11c367ca855630618.png
There is a reading, updating the payload and re-reading. On a fresh clean install, only one request is made in 5.7, while three are made in 5.8. Couldn't find a solution.
What is it and how to deal with it? And do you have to fight?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Uvarov, 2019-05-30
@primevendetta

Answer found
In Laravel 5.8, changes were made to the Illuminate/Session/Middleware/StartSession.php proxy
The handle method was cleaned up and rewritten. After the successful configuration of the session, a call to the fourth method, saveSession, was added to the already existing calls to 3 methods, and a new comment was given.

$this->collectGarbage($session);

$this->storeCurrentUrl($request, $session);

$this->addCookieToResponse($response, $session);

// Again, if the session has been configured we will need to close out the session
// so that the attributes may be persisted to some storage medium. We will also
// add the session identifier cookie to the application response headers now.
$this->saveSession($request);

In other words, now with a successful session configuration, the timestamp will be stored not only in the cookie (as before), but also in the database itself, after which the already changed session will be requested with a new request.
Here is such an update of the framework core for +2 requests occurred in version 5.8
Actually commit

T
ThunderCat, 2019-05-28
@ThunderCat

It seems that this is a mechanism for tracking (in) session activity by timeout, we read the session - if it is too old - we kill it, if it is not rotten yet - we update the time of the last active access, we refresh the session from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question