Skip to content

[HttpFoundation] Precalculate expiry timestamp #14625

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

Closed
wants to merge 1 commit into from
Closed

[HttpFoundation] Precalculate expiry timestamp #14625

wants to merge 1 commit into from

Conversation

dosten
Copy link
Contributor

@dosten dosten commented May 13, 2015

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets #13955
License MIT
Doc PR -

3.0.0
-----

* PdoSessionHandler: removed the `lifetime` and `timestamp` columns in favor of `expiry` column
Copy link
Member

Choose a reason for hiding this comment

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

This would need to be added to the update file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added more info in the UPGRADE-3.0.md file, see above.

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

Choose a reason for hiding this comment

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

you can just put 0 here since this is only dummy data that will be updated by the write operation later anyway

@dosten
Copy link
Contributor Author

dosten commented May 14, 2015

@Tobion done


- Rename the `sess_time` to `sess_expiry`. In MySQL this would be:
```
ALTER TABLE `session` CHANGE `sess_time` `sess_expiry` INTEGER UNSIGNED NOT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will result in wrong expiry time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, maybe the steps must be:

  • Create a new sess_expiry column.
  • Migrate the old data: UPDATE session SET sess_expiry = sess_time + sess_lifetime;
  • Remove the sess_time and sess_lifetime columns.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping @Tobion

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@dosten
Copy link
Contributor Author

dosten commented May 23, 2015

@Tobion updated the UPGRADE-3.0.md file.

@Tobion
Copy link
Contributor

Tobion commented May 23, 2015

👍

@Tobion Tobion added the Ready label May 23, 2015
@Tobion
Copy link
Contributor

Tobion commented May 29, 2015

ping @symfony/deciders

@xabbuh
Copy link
Member

xabbuh commented May 30, 2015

Can we in a way provide a smoother upgrade path (ie. by offering a deprecation message in Symfony 2.8)?

@weaverryan
Copy link
Member

I agree. I think we should create a new class for this and deprecate the old class. We already messed this up in 2.6 with the new PdoSessionHandler and then had to add the LegacyPdoSessionHandler quickly after to help ease the upgrade path. That - like everything else we do - will give them at least on version where they can migrate from the old to the new. If we did that, this would be merged into 2.8, which again, is consistent with all our other features (no new features in only 3.0).

@Tobion
Copy link
Contributor

Tobion commented May 30, 2015

I agree is would be nicer. But how would we name the new PdoSessionHandler? If the name sucks, we have to change the name again in 3.0 which will not make the upgrade easier.

@weaverryan
Copy link
Member

@Tobion ha, so true - we don't want something like TheNewPdoSessionHandler :).

And I'm really not sure - I think about this question a lot, but I don't know a good, global answer. How about PdoExpirySessionHandler in this case? I realize it's a slippery slope (would future changes make an ever-longer name?), but I don't think we can plan for that, and we need some way to introduce this improvement in 2.8 without the BC break.

@GromNaN
Copy link
Member

GromNaN commented May 31, 2015

Is there a necessity of removing the sess_time and sess_lifetime columns ? I don't think so.

Since this sess_expiry column needs to be added for performance reasons on "large production websites", it's a pity that we have to break session databases this way.

For a smoother migration path, I would create a feature flag to enable the extra sess_expiry column.
sess_time and sess_lifetime columns get always filled and you can still enable/disable the feature anytime and re-run the SQL query to populate the sess_expiry column.

@dosten
Copy link
Contributor Author

dosten commented Jun 17, 2015

IMO the only factible way to introduce this in 2.8 is the idea proposed by @GromNaN. What do you think? If all agree, i can make the necessary changes.

@weaverryan
Copy link
Member

I think @GromNaN's idea would certainly work, though we'd need to have a lot of if statements inside the class to use different queries. But we could deprecate the old way and remove it in 3.0 (meaning only 1 version would need to have all these ugly if statements). But yea, I would like to fix this - other than the BC part, it sounds like a great win!

@dosten
Copy link
Contributor Author

dosten commented Jun 19, 2015

Ok, i will work on this.

@weaverryan
Copy link
Member

@dosten you rock :)

@Tobion
Copy link
Contributor

Tobion commented Jun 19, 2015

I think the index on the expiry column is really necessary for high loads: #15020 (comment)

@dosten
Copy link
Contributor Author

dosten commented Jun 19, 2015

I'm not a database expert, if someone knows how to create an index in mysql, sqlite, pgsql, oci or sqlsrv.. help is welcome :)

@GromNaN
Copy link
Member

GromNaN commented Jun 19, 2015

@dosten the syntax is SQL standard : https://dev.mysql.com/doc/refman/5.0/en/create-index.html

CREATE INDEX idx_sess_expiry ON session (sess_expiry);

@dosten
Copy link
Contributor Author

dosten commented Jun 28, 2015

Closing this because i'm going to create another PR over the 2.8 branch.

@dosten dosten closed this Jun 28, 2015
@dosten dosten deleted the precalculate-expiry-timestamp branch November 7, 2015 03:20
@GuilhemN
Copy link
Contributor

GuilhemN commented Feb 1, 2016

no news about this?

bcremer added a commit to bcremer/symfony that referenced this pull request Jan 26, 2017
Removed timestamp and lifetime columns in favor of expiry column.
Based on the work done in symfony#14625.

Fix symfony#13955.
robfrawley pushed a commit to src-run/symfony that referenced this pull request Mar 3, 2017
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
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
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.

6 participants