Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds session refresh functionality to pgweb, as discussed in #799. Right now it's a bit of a hack, there's quite a few TODOs and FIXMEs, and there aren't any tests. But I figured I would throw up this draft PR to start getting eyes on it.
I went with adding a new
session_expiryfield that takes an RFC 3339 timestamp. Every minute on a background goroutine it checks all of the sessions and if any of them have expired it will refresh them.There are some tradeoffs with this approach.
api.Sessionhas aSessionRefreshcallback that is used for the session refresh and initial session setup. This works well enough but it does make the callstack a little more complicated.api.Sessioncould potentially be rolled intoclient.Clientbut it seemed trickier than just a new struct. But ifSessionManagerisn't used then there has to be a different way that sessions are refreshed so it's a little weird right now.forloop withtime.Tick.api.DbClientisn't used directly anymore andapi.DbSessionis used instead, but a pointer to theclient.Clientis kept in that variable. It's an exported variable so I wasn't sure how much we care about package API breaking changes.SessionManager.Sessions()returns a map of*client.Clientand not*Session. If all of the refresh stuff was inclient.Clientthen this wouldn't be an issue.Again, just wanted to get this draft PR up. I'll keep iterating on it in the meantime. Let me know your thoughts on this approach.
Fixes #799