Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 11 commits into from

Conversation

catchamonkey
Copy link
Contributor

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

  • 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

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
@Tobion
Copy link
Contributor

Tobion commented Jul 29, 2014

Do you know how to implement locking in Mongo to prevent race conditions? See #4976

@catchamonkey
Copy link
Contributor Author

MongoDB has DB level locking itself.
Are we really talking about read your own writes here?
If so, then updating the docs to specify a read preference may be enough without forcing it here.

Either way, that is an issue currently right, not created by this PR?

@catchamonkey catchamonkey changed the title [HttpFoundation] Added support for auto expiry in MongoSbSessionHandler [HttpFoundation] Added support for auto expiry in MongoDbSessionHandler Jul 29, 2014
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

use === on boolean tests

@catchamonkey catchamonkey changed the title [HttpFoundation] Added support for auto expiry in MongoDbSessionHandler [HttpFoundation] MongoDbSessionHandler supports auto expiry and auto index creation Jul 30, 2014
@@ -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) {
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 use Yoda expressions:

false === $this->options['expiry_field']

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

Why not time() + 1?

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 used the existing testGc as the basis for this. No reason from my end then, @jmikola ?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@catchamonkey
Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@catchamonkey
Copy link
Contributor Author

Any further comments here?

@jmikola
Copy link
Contributor

jmikola commented Aug 11, 2014

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Cheers, have updated those.

@stof
Copy link
Member

stof commented Aug 11, 2014

except for the small cleanup in tests, 👍

@catchamonkey catchamonkey changed the title [HttpFoundation] MongoDbSessionHandler supports auto expiry and auto index creation [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field Aug 11, 2014
@romainneutron
Copy link
Contributor

👍

@nicolas-grekas
Copy link
Member

Thank you @catchamonkey.

nicolas-grekas added a commit that referenced this pull request Aug 13, 2014
…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
@nicolas-grekas
Copy link
Member

Closed via 4f098dc

@Tobion
Copy link
Contributor

Tobion commented Aug 13, 2014

@nicolas-grekas I didn't know you are allowed to merge into HttpFoundation?

@Tobion
Copy link
Contributor

Tobion commented Aug 13, 2014

Also since this is a new feature, it should not have been merged into 2.3

@nicolas-grekas
Copy link
Member

@fabpot being almost off line for two weeks, he asked me and @romainneutron to merge "easypicks" so that Symfony does not stand by meanwhile.
I rely on @symfony/deciders and @symfony/mergers for identifying merge-able PRs.
I merged this one based on the votes from @romainneutron and @stof , please tell me if I should revert it and cherry-pick on an other branch instead.

@stof
Copy link
Member

stof commented Aug 13, 2014

this would indeed be better in the master branch.

@Tobion if he had not merged it because of @fabpot's vacations, I would have done it though (I'm merger for the component)

@Tobion
Copy link
Contributor

Tobion commented Aug 13, 2014

ok just asking

@catchamonkey catchamonkey deleted the mongo_gc_11508 branch August 13, 2014 21:17
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull request Aug 14, 2014
nicolas-grekas added a commit that referenced this pull request Aug 14, 2014
…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
nicolas-grekas added a commit that referenced this pull request Aug 18, 2014
* 2.3:
  add missing options
  revert #11510, moved to 2.6
  [WebProfilerBundle] Fixed double height of canvas
nicolas-grekas added a commit that referenced this pull request Aug 18, 2014
* 2.4:
  add missing options
  revert #11510, moved to 2.6
  [WebProfilerBundle] Fixed double height of canvas
nicolas-grekas added a commit that referenced this pull request Aug 18, 2014
* 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
nicolas-grekas added a commit that referenced this pull request Aug 18, 2014
…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
Copy link
Contributor

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

Copy link
Contributor

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.

ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.3:
  add missing options
  revert symfony#11510, moved to 2.6
  [WebProfilerBundle] Fixed double height of canvas
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.4:
  add missing options
  revert symfony#11510, moved to 2.6
  [WebProfilerBundle] Fixed double height of canvas
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 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
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