-
Notifications
You must be signed in to change notification settings - Fork 7
Use expireAt as index #11
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
Hey @pepoviola I think we should keep both options as the I'll put the rest of the comments inline. |
db.coll_session.createIndex( { created": 1 } , { expireAfterSeconds: 300 } ) | ||
``` | ||
To enable this [expiry feature](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-at-a-specific-clock-time) at `index` for `expireAt` is created when the client `connet`. Allowing then to use this property from the session to set the expiration of the document. | ||
|
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 think we should keep both approaches in the README as well as state when you would use one over the other.
src/lib.rs
Outdated
/// ``` | ||
pub async fn connect(uri: &str, db: &str, coll_name: &str) -> mongodb::error::Result<Self> { | ||
let client = Client::with_uri_str(uri).await?; | ||
let create_index = doc! { |
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 should probably be an external initialize as suggested in the PR commit message. It would fit with the builder approach in the tide example https://github.com/jbr/tide-example/blob/main/src/main.rs#L24 and allow us to support both global and local options
} | ||
|
||
#[test] | ||
fn test_check_expired() -> async_session::Result { |
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.
👍 Thanks for including the tests upfront :)
Hi @No9, thanks for the feedback!! 😄 . I will review the comments and make those changes.
Yes, having support of both approaches is really nice. Thx! |
Hi @No9, I just review the feedback and add this two ( more like initializers ) fn Thx! |
Hey @pepoviola - Cool - This is great progress. I think it's going to need something less wordy than I see you removed the reference to 12 Factor apps. I understand that it may not be directly relevant to the I'll have a deeper look at the code later today but would good to get @jbr 's thoughts on this as well. |
Hi @No9, thanks for the feedback 😄 . I just made those changes and add the |
This library utilises the document [expiry feature](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) in mongodb to expire the session. | ||
## Overview | ||
This library allow you to utilises the document expiration feature based on a [specified number of seconds](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) or in a [specific clock time](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-at-a-specific-clock-time) supported by mongodb to expire the session. | ||
|
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 was thinking something along the lines of
"The specified number of seconds approach is designed to enable the session time out to be managed at the mongodb layer. This approach provides a globally consistent session timeout across multiple processes but has the downside that all services using the same session collection must use the same timeout value.
The specific clock time clock time approach is where you require more flexibility on your session timeouts such as a different session timeout per running service or you would prefer to manage the session time out at the process level. This is more flexible but might lead to some perceived inconsistency in session timeout depending on your upgrade/rollout strategy."
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.
Hi @No9, Neat!! If you want I can add those lines. 👍
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.
@pepoviola If you're OK with it then lets add it inbetween the content that already there
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.
Hi @No9, added 👍 . Thanks for the help!
README.md
Outdated
## Overview | ||
This library allow you to utilises the document expiration feature based on a [specified number of seconds](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) or in a [specific clock time](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-at-a-specific-clock-time) supported by mongodb to expire the session. |
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.
## Overview | |
This library allow you to utilises the document expiration feature based on a [specified number of seconds](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) or in a [specific clock time](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-at-a-specific-clock-time) supported by mongodb to expire the session. | |
## Overview | |
This library uses the document expiration feature based on a [specified number of seconds](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) or a [specific clock time](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-at-a-specific-clock-time) supported by mongodb to expire the session. |
The specified number of seconds approach is designed to enable the session time out to be managed at the mongodb layer. This approach provides a globally consistent session timeout across multiple processes but has the downside that all services using the same session collection must use the same timeout value. | ||
|
||
This library utilises the document [expiry feature](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) in mongodb to expire the session. | ||
The specific clock time clock time approach is where you require more flexibility on your session timeouts such as a different session timeout per running service or you would prefer to manage the session time out at the process level. This is more flexible but might lead to some perceived inconsistency in session timeout depending on your upgrade/rollout strategy. |
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'm curious about the word "perceived" — is it actually consistent?
db.coll_session.createIndex( { "created": 1 } , { expireAfterSeconds: 300 } ); | ||
``` | ||
|
||
Other way to set create the index is using `index_on_created` passing the amount of seconds to expiry after the session. |
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.
Other way to set create the index is using `index_on_created` passing the amount of seconds to expiry after the session. | |
Another way to set create the index is to use `index_on_created`, passing the amount of seconds to expiry after the session. |
src/lib.rs
Outdated
} | ||
} | ||
|
||
/// Create a new index for the `created` property and set the expiry ttl (in secods). |
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.
/// Create a new index for the `created` property and set the expiry ttl (in secods). | |
/// Create a new index for the `created` property and set the expiry ttl (in seconds). |
Ok(()) | ||
} | ||
|
||
/// Create a new index for the `expireAt` property, allowing to expire sessions at a specific clock time. |
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.
/// Create a new index for the `expireAt` property, allowing to expire sessions at a specific clock time. | |
/// Create a new index for the `expireAt` property, in order to expire sessions at a specific clock time. |
The specified number of seconds approach is designed to enable the session time out to be managed at the mongodb layer. This approach provides a globally consistent session timeout across multiple processes but has the downside that all services using the same session collection must use the same timeout value. | ||
|
||
This library utilises the document [expiry feature](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-after-a-specified-number-of-seconds) in mongodb to expire the session. | ||
The specific clock time clock time approach is where you require more flexibility on your session timeouts such as a different session timeout per running service or you would prefer to manage the session time out at the process level. This is more flexible but might lead to some perceived inconsistency in session timeout depending on your upgrade/rollout strategy. |
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.
The specific clock time clock time approach is where you require more flexibility on your session timeouts such as a different session timeout per running service or you would prefer to manage the session time out at the process level. This is more flexible but might lead to some perceived inconsistency in session timeout depending on your upgrade/rollout strategy. | |
The specific clock time approach is for use cases when you require more flexibility on your session timeouts such as a different session timeout per running service or you would prefer to manage the session time out at the process level. This is more flexible but might lead to some perceived inconsistency in session timeout depending on your upgrade/rollout strategy. |
Hi @No9 / @jbr, Thanks for the feedback! I updated the code according to but I have some questions related
Thanks a lot for the help! |
Hi @jbr, can you review when you have time. Thanks! |
@pepoviola thanks for mentioning me here but I think this is ultimately a @yoshuawuyts / @io9 PR to review. I don't know anything about mongo, and my only feedback was "we should provide sensible defaults so it's easy to get started," which it sounds like we're doing |
Hi @jbr, thanks! I will wait for @yoshuawuyts or @No9. |
Hi @No9 / @yoshuawuyts, I was looking the pr #9 and looks really nice!! and triggered me the idea to check if we can skip the
config
step and keep the expiry feature.I checked how this is handler in
node.js
and theconnect-mongodb-session
create an index with{expireAfterSeconds:0}
and let the session to manage the expire as an absolute value.https://github.com/mongodb-js/connect-mongodb-session/blob/master/index.js#L88-L94
I make some changes to mimic this behavior, but I don't know if creating the
index
in theconnect
function is the best way or we can add something likefn initialize
to be called one time to create this index.Also, mongodb runs the background process to delete expired items every 60 seconds, so any value of expire lower than that will not be respected.
I could be wrong on this idea and any feedback is welcome 😄
Thanks!