-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Precalculate session expiry timestamp #21857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HttpFoundation] Precalculate session expiry timestamp #21857
Conversation
Removed timestamp and lifetime columns in favor of expiry column. Based on the work done in symfony#14625. Fix symfony#13955. Implemented CR suggestions from nicolas-grekas
de28661
to
50e01b1
Compare
I've added indexes to the new time column for MySQL, SQLite, and PgSQL, but I'm not sure how to do so with the MySQL $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->timeCol INTEGER UNSIGNED NOT NULL, KEY {$this->table}_{$this->timeCol}_idx ($this->timeCol)) COLLATE utf8_bin, ENGINE = InnoDB"; CREATE TABLE `sessions` (`sess_id` varbinary(128) NOT NULL, `sess_data` blob NOT NULL, `sess_time` int(10) unsigned NOT NULL, PRIMARY KEY (`sess_id`), KEY `sessions_sess_time_idx` (`sess_time`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin SQLite $sql = "BEGIN; CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->timeCol INTEGER NOT NULL); CREATE INDEX {$this->table}_{$this->timeCol}_idx ON $this->table ($this->timeCol); COMMIT"; BEGIN; CREATE TABLE sessions (sess_id TEXT NOT NULL PRIMARY KEY, sess_data BLOB NOT NULL, sess_time INTEGER NOT NULL); CREATE INDEX sessions_sess_time_idx ON sessions (sess_time); COMMIT; PgSQL $sql = "BEGIN; CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->timeCol INTEGER NOT NULL); CREATE INDEX {$this->table}_{$this->timeCol}_idx ON $this->table ($this->timeCol); COMMIT" BEGIN; CREATE TABLE sessions (sess_id VARCHAR(128) NOT NULL PRIMARY KEY, sess_data BYTEA NOT NULL, sess_time INTEGER NOT NULL); CREATE INDEX sessions_sess_time_idx ON sessions (sess_time); COMMIT Anyone have any insight into the proper syntax for the |
…indexes/revert removed code
50e01b1
to
0fa0c5a
Compare
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
UPGRADE-3.3.md
Outdated
HttpFoundation | ||
-------------- | ||
|
||
* The `PdoSessionHandler` option `db_lifetime_col` has been deprecated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add an entry to the UPGRADE-4.0.md
file talking about the removal of the column.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
…_col to db_time_col
} else { | ||
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); | ||
$mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB); | ||
$mergeStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this removal looks wrong to me. You need to handle the legacy way too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof The legacy tests pass as-is. Should it still be added back with the same assignment as before (the current Unix time)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same than @stof to me also
Calling out again to see if anyone has knowledge of and/or access to an Oracle ( |
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
@@ -510,7 +546,7 @@ private function doRead($sessionId) | |||
$sessionRows = $selectStmt->fetchAll(\PDO::FETCH_NUM); | |||
|
|||
if ($sessionRows) { | |||
if ($sessionRows[0][1] + $sessionRows[0][2] < time()) { | |||
if ($sessionRows[0][1] < time() || (isset($sessionRows[0][2]) && $sessionRows[0][1] + $sessionRows[0][2] < time())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would base this check on a ternary check for false === $this->lifetimeCol
, so that it's clearer and easier to spot that this needs to be changed in 4.0
src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
Show resolved
Hide resolved
$insertStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); | ||
$insertStmt->bindValue(':data', '', \PDO::PARAM_LOB); | ||
$insertStmt->bindValue(':lifetime', 0, \PDO::PARAM_INT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be conditional
@@ -629,9 +671,9 @@ private function getSelectSql() | |||
case 'mysql': | |||
case 'oci': | |||
case 'pgsql': | |||
return "SELECT $this->dataCol, $this->lifetimeCol, $this->timeCol FROM $this->table WHERE $this->idCol = :id FOR UPDATE"; | |||
return "SELECT $this->dataCol, $this->timeCol FROM $this->table WHERE $this->idCol = :id FOR UPDATE"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conditional also (we should fetch the column when false !== $this->lifetimeCol
(same below)
ping @robfrawley |
Otherwise, I need to amend a few things per some comments/reviews, but the above is a blocker for me ATM, as I have no experience using the |
@robfrawley is this really a blocker? I mean: if we are index-less in this iteration, it's fine to me, the code would still be better than today for many ppl, and not worse for oci/sqlsrv, isn't it? WOuld you have time to rebase/finish by the end of the week? |
@nicolas-grekas If you don't consider it a blocker to only support indexes on select drivers, I'm happy to rebase and address any remaining comments. Doing so by the end of the week shouldn't be an issue, either. |
@robfrawley looking forward to it thanks :) |
ping @robfrawley, this might be moved to 4.1 very soon :) |
I'm moving this PR to 4.1, we're already late in feat freeze. |
@robfrawley Still interested in finishing this one? For the record, I agree with @nicolas-grekas about support for OCI and mssql. |
@nicolas-grekas @fabpot Fair enough. I can definitely finish this up without index support for oci/sqlsrv. I'll take a look at the end of next week. Likely won't get to it sooner. |
Anyone willing to take over this one? It's almost finished AFAICR. /cc @symfony/deciders |
If nobody is willing to take over this one, I'm going to close it. Might be something we can work on in the upcoming Hackaton. |
+1 this would be great to be merged, we have some issues with this as well. |
i will take over this one, thanks for your work @robfrawley |
Continued in #33169 |
… (azjezz) This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Precalculate session expiry timestamp | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #13955, #21423, #14625 | License | MIT Continued work from the original PR #21423 / #21857 Commits ------- 066000a [HttpFoundation] Precalculate session expiry timestamp
Continued work from the original PR #21423.
Todo: