Skip to content

Commit

Permalink
[plugins] When a user clicks the "Reload all repositories" button
Browse files Browse the repository at this point in the history
manually in the plugin manager, then force a reload of the repositories
and don't rely on cached copies of the repo manifest

Otherwise it's not possible to force a refresh on certain types of
plugin repositories where it's not possible to modify the Cache-Control
attribute of the repo

Note that to avoid unnecessary server load, we still use cached
copies during startup and by default. It's only when a user explicitly
hits the "Reload all repositories" button that we force a non-cached
fetch.

Fixes #34351
  • Loading branch information
nyalldawson committed May 28, 2020
1 parent 4eb10f2 commit 98603b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/pyplugin_installer/installer.py
Expand Up @@ -119,7 +119,7 @@ def fetchAvailablePlugins(self, reloadMode):

for key in repositories.allEnabled():
if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again
repositories.requestFetching(key)
repositories.requestFetching(key, force_reload=reloadMode)

if repositories.fetchingInProgress():
fetchDlg = QgsPluginInstallerFetchingDialog(iface.mainWindow())
Expand Down
4 changes: 3 additions & 1 deletion python/pyplugin_installer/installer_data.py
Expand Up @@ -316,7 +316,7 @@ def load(self):
settings.endGroup()

# ----------------------------------------- #
def requestFetching(self, key, url=None, redirectionCounter=0):
def requestFetching(self, key, url=None, redirectionCounter=0, force_reload=False):
""" start fetching the repository given by key """
self.mRepositories[key]["state"] = 1
if not url:
Expand All @@ -327,6 +327,8 @@ def requestFetching(self, key, url=None, redirectionCounter=0):
self.mRepositories[key]["QRequest"] = QNetworkRequest(url)
self.mRepositories[key]["QRequest"].setAttribute(QNetworkRequest.Attribute(QgsNetworkRequestParameters.AttributeInitiatorClass), "Relay")
self.mRepositories[key]["QRequest"].setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
if force_reload:
self.mRepositories[key]["QRequest"].setAttribute(QNetworkRequest.CacheLoadControlAttribute, QNetworkRequest.AlwaysNetwork)
authcfg = self.mRepositories[key]["authcfg"]
if authcfg and isinstance(authcfg, str):
if not QgsApplication.authManager().updateNetworkRequest(
Expand Down

0 comments on commit 98603b7

Please sign in to comment.