Separate function

main
Bob Mottram 2020-11-30 12:47:52 +00:00
parent 8adc199764
commit 73510b0c02
1 changed files with 93 additions and 42 deletions

View File

@ -106,6 +106,81 @@ def saveIndividualPostAsHtmlToCache(baseDir: str,
return False return False
def getPostFromRecent(session,
baseDir: str,
httpPrefix: str,
nickname: str, domain: str,
postJsonObject: {},
postActor: str,
personCache: {},
allowDownloads: bool,
showPublicOnly: bool,
storeToCache: bool,
boxName: str,
avatarUrl: str,
enableTimingLog: bool,
postStartTime,
pageNumber: int,
recentPostsCache: {},
maxRecentPosts: int) -> str:
"""Attempts to get the html post from the recent posts cache in memory
"""
if boxName == 'tlmedia':
return None
if showPublicOnly:
return None
tryCache = False
bmTimeline = boxName == 'bookmarks' or boxName == 'tlbookmarks'
if storeToCache or bmTimeline:
tryCache = True
if not tryCache:
return None
# update avatar if needed
if not avatarUrl:
avatarUrl = \
getPersonAvatarUrl(baseDir, postActor, personCache,
allowDownloads)
# benchmark 2.1
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 2.1 = ' + str(timeDiff))
updateAvatarImageCache(session, baseDir, httpPrefix,
postActor, avatarUrl, personCache,
allowDownloads)
# benchmark 2.2
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 2.2 = ' + str(timeDiff))
postHtml = \
loadIndividualPostAsHtmlFromCache(baseDir, nickname, domain,
postJsonObject)
if not postHtml:
return None
postHtml = preparePostFromHtmlCache(postHtml, boxName, pageNumber)
updateRecentPostsCache(recentPostsCache, maxRecentPosts,
postJsonObject, postHtml)
# benchmark 3
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 3 = ' + str(timeDiff))
return postHtml
def individualPostAsHtml(allowDownloads: bool, def individualPostAsHtml(allowDownloads: bool,
recentPostsCache: {}, maxRecentPosts: int, recentPostsCache: {}, maxRecentPosts: int,
iconsPath: str, translate: {}, iconsPath: str, translate: {},
@ -170,48 +245,24 @@ def individualPostAsHtml(allowDownloads: bool,
if pageNumber: if pageNumber:
pageNumberParam = '?page=' + str(pageNumber) pageNumberParam = '?page=' + str(pageNumber)
if (not showPublicOnly and postHtml = \
(storeToCache or boxName == 'bookmarks' or getPostFromRecent(session, baseDir,
boxName == 'tlbookmarks') and httpPrefix, nickname, domain,
boxName != 'tlmedia'): postJsonObject,
# update avatar if needed postActor,
if not avatarUrl: personCache,
avatarUrl = \ allowDownloads,
getPersonAvatarUrl(baseDir, postActor, personCache, showPublicOnly,
allowDownloads) storeToCache,
boxName,
# benchmark 2.1 avatarUrl,
if enableTimingLog: enableTimingLog,
timeDiff = int((time.time() - postStartTime) * 1000) postStartTime,
if timeDiff > 100: pageNumber,
print('TIMING INDIV ' + boxName + recentPostsCache,
' 2.1 = ' + str(timeDiff)) maxRecentPosts)
if postHtml:
updateAvatarImageCache(session, baseDir, httpPrefix, return postHtml
postActor, avatarUrl, personCache,
allowDownloads)
# benchmark 2.2
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 2.2 = ' + str(timeDiff))
postHtml = \
loadIndividualPostAsHtmlFromCache(baseDir, nickname, domain,
postJsonObject)
if postHtml:
postHtml = preparePostFromHtmlCache(postHtml, boxName, pageNumber)
updateRecentPostsCache(recentPostsCache, maxRecentPosts,
postJsonObject, postHtml)
# benchmark 3
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 3 = ' + str(timeDiff))
return postHtml
# benchmark 4 # benchmark 4
if enableTimingLog: if enableTimingLog: