Skip to content

[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

Conversation

robfrawley
Copy link
Contributor

@robfrawley robfrawley commented Mar 3, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #13955, #21423, #14625
License MIT
Doc PR TBA

Continued work from the original PR #21423.

Todo:

  • Provide legacy tests
  • Fix code style (such as yoda style)
  • Add indexes to time column (only done for MySQL, SQLite, and PgSQL)
  • Re-implement some removed code for BC
  • Add docs to UPGRADE*.md files including SQL for changing to new behavior
  • Add deprecation/removal info to UPGRADE*.md files

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
@robfrawley robfrawley changed the title [WIP] Precalculate session expiry timestamp [WIP] [HttpFoundation] Precalculate session expiry timestamp Mar 3, 2017
@robfrawley robfrawley force-pushed the feature-precalculate-session-expiry-timestamp branch from de28661 to 50e01b1 Compare March 3, 2017 17:28
@nicolas-grekas nicolas-grekas changed the title [WIP] [HttpFoundation] Precalculate session expiry timestamp [HttpFoundation] Precalculate session expiry timestamp Mar 3, 2017
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Mar 4, 2017
@robfrawley
Copy link
Contributor Author

robfrawley commented Mar 4, 2017

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 oci or sqlsrv drivers. Here are the "create table" statements I have updated so far:

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 oci and sqlsrv drivers?

@robfrawley robfrawley force-pushed the feature-precalculate-session-expiry-timestamp branch from 50e01b1 to 0fa0c5a Compare March 4, 2017 18:48
UPGRADE-3.3.md Outdated
HttpFoundation
--------------

* The `PdoSessionHandler` option `db_lifetime_col` has been deprecated.
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

} else {
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
$mergeStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
Copy link
Member

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

Copy link
Contributor Author

@robfrawley robfrawley Mar 30, 2017

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)?

Copy link
Member

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

@robfrawley
Copy link
Contributor Author

robfrawley commented Mar 30, 2017

Calling out again to see if anyone has knowledge of and/or access to an Oracle (oci driver) or MSSQL Server (sqlsrv driver); we still need to add indexes to the CREATE TABLE statements for these drivers, as has been done for the mysql, sqlite, and pgsql drivers already.

@@ -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())) {
Copy link
Member

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

$insertStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$insertStmt->bindValue(':data', '', \PDO::PARAM_LOB);
$insertStmt->bindValue(':lifetime', 0, \PDO::PARAM_INT);
Copy link
Member

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";
Copy link
Member

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)

@nicolas-grekas
Copy link
Member

ping @robfrawley

@robfrawley
Copy link
Contributor Author

#21857 (comment):

Calling out again to see if anyone has knowledge of and/or access to an Oracle (oci driver) or MSSQL Server (sqlsrv driver); we still need to add indexes to the CREATE TABLE statements for these drivers, as has been done for the mysql, sqlite, and pgsql drivers already.

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 oci and sqlsrv drivers, and no access to these databases to test, either.

@nicolas-grekas
Copy link
Member

@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?

@robfrawley
Copy link
Contributor Author

@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.

@nicolas-grekas
Copy link
Member

@robfrawley looking forward to it thanks :)

@nicolas-grekas
Copy link
Member

ping @robfrawley, this might be moved to 4.1 very soon :)

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 12, 2017
@nicolas-grekas
Copy link
Member

I'm moving this PR to 4.1, we're already late in feat freeze.

@fabpot
Copy link
Member

fabpot commented Mar 31, 2018

@robfrawley Still interested in finishing this one? For the record, I agree with @nicolas-grekas about support for OCI and mssql.

@robfrawley
Copy link
Contributor Author

@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.

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@fabpot
Copy link
Member

fabpot commented Oct 10, 2018

Anyone willing to take over this one? It's almost finished AFAICR. /cc @symfony/deciders

@fabpot
Copy link
Member

fabpot commented Mar 24, 2019

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.

@vargedo
Copy link

vargedo commented Jul 22, 2019

+1 this would be great to be merged, we have some issues with this as well.

@azjezz
Copy link
Contributor

azjezz commented Aug 14, 2019

i will take over this one, thanks for your work @robfrawley

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 15, 2019

Continued in #33169
Thank you @robfrawley!

nicolas-grekas added a commit that referenced this pull request Aug 20, 2019
… (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
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants