parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

fix: Parse Server option `extendSessionOnUse` not working for session lengths < 24 hours

Open vivekjoshi556 opened this issue 1 year ago • 10 comments

Pull Request

This PR helps with dynamically extending session based on session Length.

Issue

Closes: #8981

Approach

I followed a similar approach to what @mman suggested here.

Tasks

  • [x] Add tests
  • [ ] Add changes to documentation (guides, repository pages, code comments)

vivekjoshi556 avatar May 01 '24 04:05 vivekjoshi556

Thanks for opening this pull request!

Hello @mman, You mentioned that you would beta test. Please look at the solution and let me know what you think.

vivekjoshi556 avatar May 01 '24 04:05 vivekjoshi556

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.15%. Comparing base (f1469c6) to head (57f8283). Report is 13 commits behind head on alpha.

:exclamation: Current head 57f8283 differs from pull request most recent head c99c48b

Please upload reports for the commit c99c48b to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #9113      +/-   ##
==========================================
+ Coverage   94.13%   94.15%   +0.01%     
==========================================
  Files         186      186              
  Lines       14687    14726      +39     
==========================================
+ Hits        13826    13865      +39     
  Misses        861      861              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 01 '24 04:05 codecov[bot]

Thanks a lot @vivekjoshi556, I will take a look first thing next week, now OOO.

mman avatar May 01 '24 09:05 mman

Hey @mman. Just wanted to check if you got some time to look at the PR.

vivekjoshi556 avatar May 06 '24 13:05 vivekjoshi556

@vivekjoshi556 The code looks nice and clean, the tests as well. Will try to deploy to my stage env later today.

mman avatar May 06 '24 14:05 mman

Hey @mman Just wanted to check in again.

@mtrezza if you have inputs as well, please let me know.

There is a minor issue with linting I'll fix it in the next push, anything else let me know.

vivekjoshi556 avatar May 10 '24 11:05 vivekjoshi556

This fix just shifts the problem downwards from 24 hours to 1 minute. Because for a session length of <1 minute, the problem in https://github.com/parse-community/parse-server/issues/8981 persists.

I wonder whether we need such a complex logic for this. If I understand https://github.com/parse-community/parse-server/issues/8981#issuecomment-1976147677 correctly, the purpose of this logic is to find a middle ground between:

  • extending the session on every request --> con: high DB writes
  • ensuring that the session extends before it expires --> con: session would never get extended

Wouldn't it be simpler to extend the session when the remaining session token validity time reached < 50% of the session length?

For example:

  • session length 1 year --> session extends if remaining time is < 182 days
  • session length 1 day --> session extends if remaining time is < 12 hours
  • session length 1 hour --> session extends if remaining time is < 30 mins
  • session length 1 minute --> session extends if remaining time is < 30 secs

Pros:

  • Simple to document and understand
  • This adapts dynamically to the session length, instead of some arbitrary extension trigger times
  • It's easy to make this configurable via a new Parse Server option in the future, by letting a developer configure the threshold, e.g. 50% as in examples above.

And could you please document this new behavior in the Parse Server option extendSessionOnUse?

mtrezza avatar May 10 '24 13:05 mtrezza

@vivekjoshi556 Just a friendly ping here; if you could simplify the logic and add the functionality description to the option docs (this repo, not the docs repo), then we could go ahead and merge.

mtrezza avatar May 14 '24 22:05 mtrezza

So sorry just got a bit swamped with work. Give me some time

vivekjoshi556 avatar May 15 '24 10:05 vivekjoshi556

@mtrezza I have made the mentioned changes. Please let me know if anything else needs to be done.

vivekjoshi556 avatar May 27 '24 03:05 vivekjoshi556

🎉 This change has been released in version 7.1.0-alpha.9

parseplatformorg avatar May 27 '24 14:05 parseplatformorg

@vivekjoshi556 Excellent, very clean code, putting into production :)

mman avatar May 27 '24 14:05 mman

🎉 This change has been released in version 7.1.0-beta.1

parseplatformorg avatar Jun 30 '24 02:06 parseplatformorg

🎉 This change has been released in version 7.1.0

parseplatformorg avatar Jun 30 '24 02:06 parseplatformorg