Skip to content

Add-on store: Improve refreshing the cache#15071

Merged
seanbudd merged 18 commits into
nvaccess:masterfrom
nvdaes:refreshCache
Jul 6, 2023
Merged

Add-on store: Improve refreshing the cache#15071
seanbudd merged 18 commits into
nvaccess:masterfrom
nvdaes:refreshCache

Conversation

@nvdaes

@nvdaes nvdaes commented Jun 28, 2023

Copy link
Copy Markdown
Collaborator
  • Refresh cache based on cache Hash from NV Access server
  • Don't use datetime to refresh cache

Link to issue number:

Fixes #15034
Fixes #15077

Summary of the issue:

The store data cache is refreshed every 6 hours. This may not be enough and it's desirable to add a mechanism to refresh it making a small request to the server, so we can request data just when a new commit has been done to the views branch of the nvaccess/addon-datastore repo.

Description of user facing changes

When opening the add-on store, if there has been changes on the server, the cached data should be updated.

Description of development approach

  • In dataManager, a function has been added to get the cacheHash from NV Access server.
  • References to date, including parameters of functions, have been replaced with variables which hold the value of the cache hash.
  • try... except clauses have been used to ensure that .json files which store cache data are valid,though perhaps a jsonschema will be more robust and will allow to control data types.
  • network.py has been tweaked.

Testing strategy:

  • Wifi has been deactivated and the store has been opened. When pressing tab to select available and updatable add-ons, and also when the checkbox to get incompatible add-ons has been checked, error messages have been displayed, since NVDA tried to get the hash.
    Also, manual tests have confirmed that new add-ons sent to the store have been retrieved.

Known issues with pull request:

When the checkbox to get incompatible add-ons is checked, the add-ons list is refreshed and this may take some seconds.

Change log entries:

n/a
New features
Changes
Bug fixes
For Developers

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • Security precautions taken.

@nvdaes

nvdaes commented Jun 28, 2023

Copy link
Copy Markdown
Collaborator Author

cc: @josephsl

@josephsl

josephsl commented Jun 28, 2023 via email

Copy link
Copy Markdown
Contributor

Comment thread source/_addonStore/dataManager.py Outdated
Co-authored-by: Leonard de Ruijter <leonardder@users.noreply.github.com>
@nvdaes

nvdaes commented Jun 29, 2023

Copy link
Copy Markdown
Collaborator Author

Thanks @josephsl and @LeonarddeR for your comments.

@nvdaes

nvdaes commented Jul 1, 2023

Copy link
Copy Markdown
Collaborator Author

I think that this is ready for review.

@nvdaes nvdaes marked this pull request as ready for review July 1, 2023 03:34
@nvdaes nvdaes requested a review from a team as a code owner July 1, 2023 03:34
@nvdaes nvdaes requested a review from seanbudd July 1, 2023 03:34
@seanbudd seanbudd changed the title refreshCache Add-on store: Improve refreshing the cache Jul 2, 2023
Comment thread source/_addonStore/dataManager.py Outdated
Comment thread source/_addonStore/dataManager.py
Comment thread source/_addonStore/dataManager.py Outdated
Comment thread source/_addonStore/models/addon.py Outdated
Comment thread source/_addonStore/network.py Outdated
Comment thread source/_addonStore/dataManager.py Outdated
Comment thread source/_addonStore/dataManager.py Outdated
Comment thread source/_addonStore/dataManager.py Outdated
Comment thread source/_addonStore/dataManager.py
@seanbudd seanbudd marked this pull request as draft July 3, 2023 00:05
Comment thread source/_addonStore/dataManager.py Outdated
@@ -142,10 +157,10 @@ def _getCachedAddonData(self, cacheFilePath: str) -> Optional[CachedAddonsModel]
cacheData = json.load(cacheFile)

@seanbudd seanbudd Jul 3, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also look at fixing #15077, at the same time as #15071 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nvdaes, you have asked me to test this PR in #15077 (comment).

Testing from source on latest commit (dfe1b22) with the file from #15077, the issue is still present.

You should add a try/except around the two following lines in _getCachedAddonData:

 		with open(cacheFilePath, 'r') as cacheFile:
			cacheData = json.load(cacheFile)

@nvdaes

nvdaes commented Jul 3, 2023

Copy link
Copy Markdown
Collaborator Author
  • cacheHash = cacheData.get("cacheHash")
    

is there a reason get is used here?

This was to avoid an error if the "cacheHash" key doesn't exist, but now I'll see if I can fix this.

@nvdaes

nvdaes commented Jul 3, 2023

Copy link
Copy Markdown
Collaborator Author

@seanbudd Hope your comments are correctly addressed. Imo it would be better to create a jsonSchema for a better maintenance and control of type values in future, but for now I've used try...except KeyError to fix #15077

@nvdaes

nvdaes commented Jul 3, 2023

Copy link
Copy Markdown
Collaborator Author

I've made another commit and I'll way for further comments @seanbudd

@nvdaes nvdaes requested a review from seanbudd July 3, 2023 10:04
@nvdaes nvdaes marked this pull request as ready for review July 3, 2023 10:37
@nvdaes

nvdaes commented Jul 3, 2023

Copy link
Copy Markdown
Collaborator Author

Hi @CyrilleB79 . You wrote:

You should add a try/except around the two following lines in _getCachedAddonData:

I've tried to address your comment. Please try again if you can.

@CyrilleB79

Copy link
Copy Markdown
Contributor

Hi @CyrilleB79 . You wrote:

You should add a try/except around the two following lines in _getCachedAddonData:

I've tried to address your comment. Please try again if you can.

Yes NVDA loads successfully now and the file seems to be recreated.

Having a look at the code, I would say that it may be valuable to log the exception or at least a debugWarning message. Indeed it's not expected to fail loading the file:

  • Either someone has modified it manually; in this case there is nothing to do.
  • Or it's an old incompatible version coming from an older alpha; nothing to do either.
  • Or there is a bug in our current code and logging a warning would help to debug it.

I wonder if making a backup of this badly formatted file before overwriting it would be needed in case of a bug to help debugging it.

Surely the current PR fix the startup issue described in #15077. But is there an issue remaining? Why was a badly formatted file created initially? @seanbudd what is your opinion on this?

@nvdaes

nvdaes commented Jul 3, 2023

Copy link
Copy Markdown
Collaborator Author

Thanks Cyrille: I had thought about this. Let"s wait for Sean feedback in case he has some preference about the kind of warning that maybe writen in the log.

@seanbudd

seanbudd commented Jul 4, 2023

Copy link
Copy Markdown
Member

I wonder if making a backup of this badly formatted file before overwriting it would be needed in case of a bug to help debugging it.

I think this is unnecessary as these caches are not an important state file - and can easily be wiped and replaced

@seanbudd

seanbudd commented Jul 4, 2023

Copy link
Copy Markdown
Member

@nvdaes - could you add references to #15077 and otherwise update the PR descripition?

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes generally look good to me

Comment thread source/_addonStore/network.py Outdated
Comment thread source/_addonStore/network.py Outdated
Comment thread source/_addonStore/network.py Outdated
Comment thread source/_addonStore/network.py Outdated
Comment thread source/_addonStore/dataManager.py
Comment thread source/_addonStore/dataManager.py
@nvdaes

nvdaes commented Jul 4, 2023 via email

Copy link
Copy Markdown
Collaborator Author

@seanbudd seanbudd marked this pull request as draft July 4, 2023 05:07
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit d9a8f1ae2c

@nvdaes

nvdaes commented Jul 4, 2023

Copy link
Copy Markdown
Collaborator Author

@seanbudd 24o53:

In case it was confusing the suggestion here as to remove the unused variable _baseURL

I think it's all done.

@nvdaes nvdaes requested a review from seanbudd July 4, 2023 05:37
@nvdaes nvdaes marked this pull request as ready for review July 4, 2023 06:21

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just 1 minor suggestion

Comment thread source/_addonStore/dataManager.py Outdated
not self._compatibleAddonCache
or self._compatibleAddonCache.nvdaAPIVersion != addonAPIVersion.CURRENT
or _DataManager._cachePeriod < (datetime.now() - self._compatibleAddonCache.cachedAt)
or cacheHash and (self._compatibleAddonCache.cacheHash != cacheHash)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should always refresh the cache if fetching the cacheHash fails.
This assumes we can treat "None" as a valid cacheHash,

Suggested change
or cacheHash and (self._compatibleAddonCache.cacheHash != cacheHash)
or cacheHash is None
or self._compatibleAddonCache.cacheHash != cacheHash

Comment thread source/_addonStore/dataManager.py Outdated
shouldRefreshData = (
not self._latestAddonCache
or _DataManager._cachePeriod < (datetime.now() - self._latestAddonCache.cachedAt)
or cacheHash and (self._latestAddonCache.cacheHash != cacheHash)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here re: cacheHash being None

Suggested change
or cacheHash and (self._latestAddonCache.cacheHash != cacheHash)
or cacheHash is None
or self._compatibleAddonCache.cacheHash != cacheHash

@seanbudd seanbudd marked this pull request as draft July 6, 2023 02:42
@nvdaes nvdaes marked this pull request as ready for review July 6, 2023 03:19
@nvdaes nvdaes requested a review from seanbudd July 6, 2023 03:20

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nvdaes

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 28d1edcadb

@seanbudd seanbudd merged commit 54a4ec5 into nvaccess:master Jul 6, 2023
@nvaccessAuto nvaccessAuto added this to the 2023.2 milestone Jul 6, 2023
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 this pull request may close these issues.

Critical error when starting alpha Add-on store: add ability to manually refresh store data cache

7 participants