Skip to content

Sessions aren't correctly stored #3

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
yoshuawuyts opened this issue Jul 28, 2020 · 4 comments · Fixed by #4
Closed

Sessions aren't correctly stored #3

yoshuawuyts opened this issue Jul 28, 2020 · 4 comments · Fixed by #4

Comments

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Jul 28, 2020

Each request we make creates a new session id entry in the database. It seems we're probably doing something wrong. The result is that the counter isn't updated and we keep opening new sessions.

Related issues: #1, http-rs/async-session#10, http-rs/tide#664

cc/ @lrlna

Repro

  1. Clone mongodb-session-example tide#664
  2. cargo run --example session

Screenshot

Screenshot 2020-07-28 13 59 21

@lrlna
Copy link
Collaborator

lrlna commented Jul 28, 2020

@yoshuawuyts when you store a session you should be updating an already existing session.

So this line here should do a find_one_and_update.

Something to consider for store_session function is whether this session would already exist when you store it, or there is a possibility of a brand new session. If there is a possibility of a brand new session, I'd do something like this:

  • find_one_and_update. If there are no results returned, you know that this session doesn't exist.
  • if the session doesn't exist, insert_one instead.

@mbroadst
Copy link

@lrlna sounds like you're talking about an upsert here, perhaps you're looking for replace_one

yoshuawuyts added a commit that referenced this issue Jul 28, 2020
yoshuawuyts added a commit that referenced this issue Jul 28, 2020
@yoshuawuyts
Copy link
Member Author

yoshuawuyts commented Jul 28, 2020

@lrlna @mbroadst thanks heaps; tested and filed a fix in #4 🎉

@lrlna
Copy link
Collaborator

lrlna commented Jul 28, 2020

@mbroadst i was precisely looking for an upsert but couldn't find replace_one in docs.rs 🤦‍♀️

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

Successfully merging a pull request may close this issue.

3 participants