Skip to content
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

Store session creation date in session backends #10

Open
yoshuawuyts opened this issue Jul 28, 2020 · 3 comments
Open

Store session creation date in session backends #10

yoshuawuyts opened this issue Jul 28, 2020 · 3 comments

Comments

@yoshuawuyts
Copy link
Member

I was debugging mongo and couldn't find the creation date in the session store. We should probably track this for all sessions; even if not tracked by UTC it does help with debugging. Perhaps the individual backends provide primitives for this as well that we can use.

Screenshot

I was trying to find from this screenshot which sessions were created today. It doesn't say, heh.

Screenshot 2020-07-28 13 59 21

@yoshuawuyts yoshuawuyts changed the title Store session creation date in sessions Store session creation date in session backends Jul 28, 2020
@yoshuawuyts
Copy link
Member Author

This view can be recreated by running this branch http-rs/tide#664 and introspecting the database through MongoDB Compass.

@jbr
Copy link
Member

jbr commented Aug 3, 2020

Is there a production use case for this or is it just for development/debugging? If the latter, would this be sufficient:

    use chrono::{DateTime, Utc};
    app.with(Before(|mut request: Request<_>| async move {
        let session = request.session_mut();
        if session.get_raw("created").is_none() {
            session.insert("created", Utc::now()).unwrap();
        }
        request
    }));

Then it would be available within the serialized json data

Alternatively, there's no reason a session store couldn't add additional data to the record

@yoshuawuyts
Copy link
Member Author

Alternatively, there's no reason a session store couldn't add additional data to the record

Yeah that's what I was thinking -- for example MongoDB has a native DateTime object that can be used for serialization. For the default backends we expose it'd probably be useful to track creation time + time of last update. I don't believe MongoDB tracks this itself (it does serialize the creation date in the ID, but it can't be queried for afaict), so making that data available would be be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants