-
-
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
Changes from 1 commit
bb336a5
796b18a
2d8b2bd
4d42f32
cb5e562
d748743
2f8742e
fc962db
b55c63b
88b256c
9744f61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…or expiry checks
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ public function write($sessionId, $data) | |
$fields[$this->options['expiry_field']] = $expiry; | ||
|
||
$this->getCollection()->createIndex( | ||
[$this->options['time_field'] => 1], | ||
[$this->options['expiry_field'] => 1], | ||
['expireAfterSeconds' => 0] | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the reasoning for putting this here, but issuing a createIndexes command with each session write is not a good idea. We're also not using the Small side note: this might also lead to unexpected behavior if someone on a very old MongoDB version tries to use I assume there will be a PR against symfony-docs to complement this. We should just point users to the MongoDB documentation so that they can create the TTL index themselves if necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK I see the concern, I was really just trying to make using this option as simple as possible and have the indexes handled automatically for you. There isn't actually anything in the docs about using the MongoDbSessionHandler in general that I can add this to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do you have citations for that? I'd be curious to know what other open-source projects are doing this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, to be honest I can't go any further with it that applications I have been involved in. Some reference, but nothing hard I guess. http://stackoverflow.com/questions/7000777/mongodb-when-to-call-ensureindex It can be a documented edit and I'll remove from this code, at least the developer is in control I guess? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd suggest leaving it in a comment (as I did for the ZF class) or in the documentation (if this ever gets an entry). Anecdotally, index creation for ODM is left to console commands, as we consider it part of the schema creation process. The best practice is definitely to leave index creation as part of the deployment process. There are some references in that Stack Overflow thread to doing it when the application starts, but that's likely for Java and the like, where the application and app server are one and the same (vs. PHP, where we'd be doing it during a web request). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Have updated it. |
||
} | ||
|
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 line will be called on each call to
write
? I'm not sure, but I thinks you should useensureIndex
, and move this part in gc. What do you think?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.
ensureIndex is deprecated, createIndex actually does the same thing but is the new one to use.
See: http://php.net/manual/en/mongocollection.ensureindex.php
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.
Thank you