reddit-moderator-toolbox icon indicating copy to clipboard operation
reddit-moderator-toolbox copied to clipboard

Fix userDetails cache not set and used

Open creesch opened this issue 2 years ago • 2 comments

As the title says, the userDetails was never set and also not used. As it is effectively always called on toolbox init the cached modhash and username don't really need to be fetched again.

Note: PR done in the github web version of vscode so not actually tested yet.

creesch avatar Aug 25 '22 07:08 creesch

Note: PR done in the github web version of vscode so not actually tested yet.

Tested and everything works as expected.

creesch avatar Aug 25 '22 14:08 creesch

Reworked to put the cache lookup in userDetailsPromise instead of repeating it in the other functions that rely on getUserDetails(). Should be good to go now.

eritbh avatar Aug 26 '22 21:08 eritbh

This should be ready to merge now:

  • On page load it will always attempt to fetch user details through the API.
  • When succeeded, it now actually does set the cache.
  • The cache is only used as a fallback. For example, when reddit is having backend issues. The reason for only using it as a fallback is that people also switch users and log out, using cached data here would cause issues.
  • The details are kept around in a resolved promise (I was not aware this is a thing, seems like magic but that is mostly on my knowledge gap there) and through there used by the getModhash and getCurrentUser functions.

creesch avatar Sep 03 '22 07:09 creesch