-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field #11510
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
This adds a config option that disables the PHP GC method call from doing anything, and also means that the write method sets up the auto expiring index
Do you know how to implement locking in Mongo to prevent race conditions? See #4976 |
MongoDB has DB level locking itself. Either way, that is an issue currently right, not created by this PR? |
@@ -109,11 +110,14 @@ public function gc($maxlifetime) | |||
* | |||
* See: http://docs.mongodb.org/manual/tutorial/expire-data/ | |||
*/ | |||
$time = new \MongoDate(time() - $maxlifetime); | |||
if ($this->options['expiry_field'] == false) { |
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.
use ===
on boolean tests
@@ -109,11 +110,14 @@ public function gc($maxlifetime) | |||
* | |||
* See: http://docs.mongodb.org/manual/tutorial/expire-data/ | |||
*/ | |||
$time = new \MongoDate(time() - $maxlifetime); | |||
if ($this->options['expiry_field'] === false) { |
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 use Yoda expressions:
false === $this->options['expiry_field']
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.
Ah yes, will modify.
->method('remove') | ||
->will($this->returnCallback(function ($criteria) use ($that) { | ||
$that->assertInstanceOf('MongoDate', $criteria[$that->options['time_field']]['$lt']); | ||
$that->assertGreaterThanOrEqual(time() - -1, $criteria[$that->options['time_field']]['$lt']->sec); |
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.
Why not time() + 1
?
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 used the existing testGc as the basis for this. No reason from my end then, @jmikola ?
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 sorted through the git history and this goes back to @Baachi's original unit tests in 40df3bf, which were later refactored in f2d8a8a.
Looking at it now, I have no idea why gc()
is called with -1
below, but I think the syntax above (time() - -1
) is just for readability, as it makes it clear that the criteria subtracts the $maxlifetime
argument from time()
. I actually don't see any documentation in PHP about negative session timeouts (0 means limited to the browser session). It might be best just to update all of the tests to use a positive value for the gc()
calls, and then we'll have time() - <positive number>
above.
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.
There was no especially reason, why i called gc
with -1
.
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.
OK thanks guys, i'll update these then.
Hi, What needs to be done so this can be merged? |
@@ -109,11 +110,14 @@ public function gc($maxlifetime) | |||
* | |||
* See: http://docs.mongodb.org/manual/tutorial/expire-data/ | |||
*/ | |||
$time = new \MongoDate(time() - $maxlifetime); |
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.
Rather than most of the existing method body in an if
statement, it would be preferable to simply do the following at the top of the function:
if (false !== $this->options['expiry_field']) {
return true;
}
That keeps the diff smaller, which benefits anyone working on the file in the future.
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.
👍
Any further comments here? |
I have no further input. I think @stof can give this a final look, or some of the core team voters can chime in. |
$this->mongo->expects($this->never()) | ||
->method('selectCollection') | ||
->with($this->options['database'], $this->options['collection']) | ||
->will($this->returnValue($collection)); |
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.
will()
and with
can be removed, as you expect it will never be called
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.
👍 Cheers, have updated those.
except for the small cleanup in tests, 👍 |
👍 |
Thank you @catchamonkey. |
…xpiry via configurable expiry_field (catchamonkey) This PR was squashed before being merged into the 2.3 branch (closes #11510). Discussion ---------- [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11508 | License | MIT | Doc PR | no ToDo * [x] Fix Tests Looking for feedback on this early PR. This adds a config option that disables the PHP GC method call from doing anything, It also means that the write method sets up the auto expiring index. Ref: #11508 Commits ------- b56b740 [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field
Closed via 4f098dc |
@nicolas-grekas I didn't know you are allowed to merge into HttpFoundation? |
Also since this is a new feature, it should not have been merged into 2.3 |
@fabpot being almost off line for two weeks, he asked me and @romainneutron to merge "easypicks" so that Symfony does not stand by meanwhile. |
ok just asking |
…ekas) This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] revert #11510, moved to 2.6 | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | none This reverts PR #11510 from 2.3. Commits ------- fb120c7 revert #11510, moved to 2.6
* 2.3: add missing options revert #11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
* 2.4: add missing options revert #11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
* 2.5: add missing options [Form] Fixed ValidatorExtension to work with the 2.5 Validation API revert #11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
…xpiry via configurable expiry_field (catchamonkey) This PR was merged into the 2.6-dev branch. Discussion ---------- [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11508 | License | MIT | Doc PR | no This PR applies #11510 to master instead of 2.3 Should be merged on master: - [x] after #11667 is merged to 2.3 - [x] and after 2.3 is merged back to master Commits ------- beca900 [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field
$this->options['time_field'] => new \MongoDate(), | ||
); | ||
|
||
/* Note: As discussed in the gc method of this class. You can utilise |
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 comment should be in the phpdoc where it is actually visible to users
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.
Probably best to submit a new PR with that chance, since this has already been merged and closed.
* 2.3: add missing options revert symfony#11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
* 2.4: add missing options revert symfony#11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
* 2.5: add missing options [Form] Fixed ValidatorExtension to work with the 2.5 Validation API revert symfony#11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
ToDo
Looking for feedback on this early PR.
This adds a config option that disables the PHP GC method call from doing anything,
It also means that the write method sets up the auto expiring index.
Ref: #11508