async-session icon indicating copy to clipboard operation
async-session copied to clipboard

Store session creation date in session backends

Open yoshuawuyts opened this issue 5 years ago • 3 comments

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 avatar Jul 28 '20 12:07 yoshuawuyts

This view can be recreated by running this branch https://github.com/http-rs/tide/pull/664 and introspecting the database through MongoDB Compass.

yoshuawuyts avatar Jul 28 '20 12:07 yoshuawuyts

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

jbr avatar Aug 03 '20 17:08 jbr

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.

yoshuawuyts avatar Aug 07 '20 10:08 yoshuawuyts