From 9fab236f04ecd01f14fb23936a7ae0c81ca89890 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 29 Aug 2020 10:39:38 +0100 Subject: [PATCH] Down download avatars at the same time as displaying the timeline --- webinterface.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/webinterface.py b/webinterface.py index 008321837..4789df5ea 100644 --- a/webinterface.py +++ b/webinterface.py @@ -199,7 +199,8 @@ def setBlogAddress(actorJson: {}, blogAddress: str) -> None: def updateAvatarImageCache(session, baseDir: str, httpPrefix: str, actor: str, avatarUrl: str, - personCache: {}, force=False) -> str: + personCache: {}, allowDownloads: bool, + force=False) -> str: """Updates the cached avatar for the given actor """ if not avatarUrl: @@ -232,7 +233,7 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str, avatarImageFilename = avatarImagePath + '.webp' else: return None - if not os.path.isfile(avatarImageFilename) or force: + if (not os.path.isfile(avatarImageFilename) or force) and allowDownloads: try: print('avatar image url: ' + avatarUrl) result = session.get(avatarUrl, @@ -283,7 +284,8 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str, actor) return None storePersonInCache(baseDir, actor, personJson, personCache) - return getPersonAvatarUrl(baseDir, actor, personCache, True) + return getPersonAvatarUrl(baseDir, actor, personCache, + allowDownloads) return None return avatarImageFilename.replace(baseDir + '/cache', '') @@ -3861,7 +3863,8 @@ def individualPostAsHtml(allowDownloads: bool, print('TIMING INDIV ' + boxName + ' 2.1 = ' + str(timeDiff)) updateAvatarImageCache(session, baseDir, httpPrefix, - postActor, avatarUrl, personCache) + postActor, avatarUrl, personCache, + allowDownloads) # benchmark 2.2 timeDiff = int((time.time() - postStartTime) * 1000) @@ -3892,10 +3895,12 @@ def individualPostAsHtml(allowDownloads: bool, allowDownloads) avatarUrl = \ updateAvatarImageCache(session, baseDir, httpPrefix, - postActor, avatarUrl, personCache) + postActor, avatarUrl, personCache, + allowDownloads) else: updateAvatarImageCache(session, baseDir, httpPrefix, - postActor, avatarUrl, personCache) + postActor, avatarUrl, personCache, + allowDownloads) # benchmark 5 timeDiff = int((time.time() - postStartTime) * 1000)