Only benchmark timeline when being displayed

main
Bob Mottram 2020-08-29 10:56:30 +01:00
parent 9fab236f04
commit 74046a9c3d
1 changed files with 155 additions and 114 deletions

View File

@ -233,6 +233,7 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
avatarImageFilename = avatarImagePath + '.webp' avatarImageFilename = avatarImagePath + '.webp'
else: else:
return None return None
if (not os.path.isfile(avatarImageFilename) or force) and allowDownloads: if (not os.path.isfile(avatarImageFilename) or force) and allowDownloads:
try: try:
print('avatar image url: ' + avatarUrl) print('avatar image url: ' + avatarUrl)
@ -3858,18 +3859,22 @@ def individualPostAsHtml(allowDownloads: bool,
allowDownloads) allowDownloads)
# benchmark 2.1 # benchmark 2.1
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 2.1 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 2.1 = ' + str(timeDiff))
updateAvatarImageCache(session, baseDir, httpPrefix, updateAvatarImageCache(session, baseDir, httpPrefix,
postActor, avatarUrl, personCache, postActor, avatarUrl, personCache,
allowDownloads) allowDownloads)
# benchmark 2.2 # benchmark 2.2
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 2.2 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 2.2 = ' + str(timeDiff))
postHtml = \ postHtml = \
loadIndividualPostAsHtmlFromCache(baseDir, nickname, domain, loadIndividualPostAsHtmlFromCache(baseDir, nickname, domain,
@ -3879,15 +3884,18 @@ def individualPostAsHtml(allowDownloads: bool,
updateRecentPostsCache(recentPostsCache, maxRecentPosts, updateRecentPostsCache(recentPostsCache, maxRecentPosts,
postJsonObject, postHtml) postJsonObject, postHtml)
# benchmark 3 # benchmark 3
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 3 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 3 = ' + str(timeDiff))
return postHtml return postHtml
# benchmark 4 # benchmark 4
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 4 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 4 = ' + str(timeDiff))
if not avatarUrl: if not avatarUrl:
avatarUrl = \ avatarUrl = \
@ -3903,9 +3911,10 @@ def individualPostAsHtml(allowDownloads: bool,
allowDownloads) allowDownloads)
# benchmark 5 # benchmark 5
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 5 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 5 = ' + str(timeDiff))
if not avatarUrl: if not avatarUrl:
avatarUrl = postActor + '/avatar.png' avatarUrl = postActor + '/avatar.png'
@ -3919,9 +3928,10 @@ def individualPostAsHtml(allowDownloads: bool,
projectVersion, httpPrefix, projectVersion, httpPrefix,
nickname, domain, 'outbox') nickname, domain, 'outbox')
# benchmark 6 # benchmark 6
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 6 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 6 = ' + str(timeDiff))
if avatarUrl2: if avatarUrl2:
avatarUrl = avatarUrl2 avatarUrl = avatarUrl2
@ -3933,9 +3943,10 @@ def individualPostAsHtml(allowDownloads: bool,
displayName, False) displayName, False)
# benchmark 7 # benchmark 7
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 7 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 7 = ' + str(timeDiff))
avatarLink = ' <a class="imageAnchor" href="' + postActor + '">' avatarLink = ' <a class="imageAnchor" href="' + postActor + '">'
avatarLink += \ avatarLink += \
@ -3991,9 +4002,10 @@ def individualPostAsHtml(allowDownloads: bool,
isAnnounced = True isAnnounced = True
# benchmark 8 # benchmark 8
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 8 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 8 = ' + str(timeDiff))
if not isinstance(postJsonObject['object'], dict): if not isinstance(postJsonObject['object'], dict):
return '' return ''
@ -4044,9 +4056,10 @@ def individualPostAsHtml(allowDownloads: bool,
'">@' + actorNickname + '@' + actorDomain + '</a>\n' '">@' + actorNickname + '@' + actorDomain + '</a>\n'
# benchmark 9 # benchmark 9
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 9 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 9 = ' + str(timeDiff))
# Show a DM icon for DMs in the inbox timeline # Show a DM icon for DMs in the inbox timeline
if showDMicon: if showDMicon:
@ -4106,16 +4119,18 @@ def individualPostAsHtml(allowDownloads: bool,
' |" src="/' + iconsDir + '/reply.png"/></a>\n' ' |" src="/' + iconsDir + '/reply.png"/></a>\n'
# benchmark 10 # benchmark 10
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 10 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 10 = ' + str(timeDiff))
isEvent = isEventPost(postJsonObject) isEvent = isEventPost(postJsonObject)
# benchmark 11 # benchmark 11
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 11 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 11 = ' + str(timeDiff))
editStr = '' editStr = ''
if fullDomain + '/users/' + nickname in postJsonObject['actor']: if fullDomain + '/users/' + nickname in postJsonObject['actor']:
@ -4171,9 +4186,10 @@ def individualPostAsHtml(allowDownloads: bool,
' |" src="/' + iconsDir + '/' + announceIcon + '"/></a>\n' ' |" src="/' + iconsDir + '/' + announceIcon + '"/></a>\n'
# benchmark 12 # benchmark 12
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 12 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 12 = ' + str(timeDiff))
# whether to show a like button # whether to show a like button
hideLikeButtonFile = \ hideLikeButtonFile = \
@ -4190,9 +4206,10 @@ def individualPostAsHtml(allowDownloads: bool,
likeCount = noOfLikes(postJsonObject) likeCount = noOfLikes(postJsonObject)
# benchmark 12.1 # benchmark 12.1
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 12.1 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 12.1 = ' + str(timeDiff))
likeCountStr = '' likeCountStr = ''
if likeCount > 0: if likeCount > 0:
@ -4207,9 +4224,10 @@ def individualPostAsHtml(allowDownloads: bool,
likeTitle = translate['Undo the like'] likeTitle = translate['Undo the like']
# benchmark 12.2 # benchmark 12.2
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 12.2 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 12.2 = ' + str(timeDiff))
likeStr = \ likeStr = \
'<a class="imageAnchor" href="/users/' + nickname + '?' + \ '<a class="imageAnchor" href="/users/' + nickname + '?' + \
@ -4225,9 +4243,10 @@ def individualPostAsHtml(allowDownloads: bool,
' |" src="/' + iconsDir + '/' + likeIcon + '"/></a>\n' ' |" src="/' + iconsDir + '/' + likeIcon + '"/></a>\n'
# benchmark 12.5 # benchmark 12.5
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 12.5 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 12.5 = ' + str(timeDiff))
bookmarkStr = '' bookmarkStr = ''
if not isModerationPost: if not isModerationPost:
@ -4239,9 +4258,10 @@ def individualPostAsHtml(allowDownloads: bool,
bookmarkLink = 'unbookmark' bookmarkLink = 'unbookmark'
bookmarkTitle = translate['Undo the bookmark'] bookmarkTitle = translate['Undo the bookmark']
# benchmark 12.6 # benchmark 12.6
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 12.6 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 12.6 = ' + str(timeDiff))
bookmarkStr = \ bookmarkStr = \
'<a class="imageAnchor" href="/users/' + nickname + '?' + \ '<a class="imageAnchor" href="/users/' + nickname + '?' + \
bookmarkLink + '=' + postJsonObject['object']['id'] + \ bookmarkLink + '=' + postJsonObject['object']['id'] + \
@ -4255,16 +4275,18 @@ def individualPostAsHtml(allowDownloads: bool,
'/' + bookmarkIcon + '"/></a>\n' '/' + bookmarkIcon + '"/></a>\n'
# benchmark 12.9 # benchmark 12.9
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 12.9 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 12.9 = ' + str(timeDiff))
isMuted = postIsMuted(baseDir, nickname, domain, postJsonObject, messageId) isMuted = postIsMuted(baseDir, nickname, domain, postJsonObject, messageId)
# benchmark 13 # benchmark 13
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 13 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 13 = ' + str(timeDiff))
deleteStr = '' deleteStr = ''
muteStr = '' muteStr = ''
@ -4305,9 +4327,10 @@ def individualPostAsHtml(allowDownloads: bool,
'" src="/' + iconsDir+'/unmute.png"/></a>\n' '" src="/' + iconsDir+'/unmute.png"/></a>\n'
# benchmark 13.1 # benchmark 13.1
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 13.1 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 13.1 = ' + str(timeDiff))
replyAvatarImageInPost = '' replyAvatarImageInPost = ''
if showRepeatIcon: if showRepeatIcon:
@ -4325,10 +4348,11 @@ def individualPostAsHtml(allowDownloads: bool,
'/repeat_inactive.png" class="announceOrReply"/>\n' '/repeat_inactive.png" class="announceOrReply"/>\n'
else: else:
# benchmark 13.2 # benchmark 13.2
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + if timeDiff > 100:
' 13.2 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName +
' 13.2 = ' + str(timeDiff))
announceNickname = None announceNickname = None
if attributedTo: if attributedTo:
announceNickname = getNicknameFromActor(attributedTo) announceNickname = getNicknameFromActor(attributedTo)
@ -4340,11 +4364,12 @@ def individualPostAsHtml(allowDownloads: bool,
getDisplayName(baseDir, attributedTo, personCache) getDisplayName(baseDir, attributedTo, personCache)
if announceDisplayName: if announceDisplayName:
# benchmark 13.3 # benchmark 13.3
timeDiff = \ if not allowDownloads:
int((time.time() - postStartTime) * 1000) timeDiff = \
if timeDiff > 100: int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + if timeDiff > 100:
' 13.3 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName +
' 13.3 = ' + str(timeDiff))
if ':' in announceDisplayName: if ':' in announceDisplayName:
announceDisplayName = \ announceDisplayName = \
@ -4353,11 +4378,12 @@ def individualPostAsHtml(allowDownloads: bool,
announceDisplayName, announceDisplayName,
False) False)
# benchmark 13.3.1 # benchmark 13.3.1
timeDiff = \ if not allowDownloads:
int((time.time() - postStartTime) * 1000) timeDiff = \
if timeDiff > 100: int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + if timeDiff > 100:
' 13.3.1 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName +
' 13.3.1 = ' + str(timeDiff))
titleStr += \ titleStr += \
' <img loading="lazy" title="' + \ ' <img loading="lazy" title="' + \
@ -4375,11 +4401,12 @@ def individualPostAsHtml(allowDownloads: bool,
personCache, allowDownloads) personCache, allowDownloads)
# benchmark 13.4 # benchmark 13.4
timeDiff = \ if not allowDownloads:
int((time.time() - postStartTime) * 1000) timeDiff = \
if timeDiff > 100: int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + if timeDiff > 100:
' 13.4 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName +
' 13.4 = ' + str(timeDiff))
if announceAvatarUrl: if announceAvatarUrl:
idx = 'Show options for this person' idx = 'Show options for this person'
@ -4452,11 +4479,14 @@ def individualPostAsHtml(allowDownloads: bool,
if replyDisplayName: if replyDisplayName:
if ':' in replyDisplayName: if ':' in replyDisplayName:
# benchmark 13.5 # benchmark 13.5
timeDiff = int((time.time() - if not allowDownloads:
postStartTime) * 1000) timeDiff = \
if timeDiff > 100: int((time.time() -
print('TIMING INDIV ' + boxName + postStartTime) * 1000)
' 13.5 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' +
boxName + ' 13.5 = ' +
str(timeDiff))
repDisp = replyDisplayName repDisp = replyDisplayName
replyDisplayName = \ replyDisplayName = \
addEmojiToDisplayName(baseDir, addEmojiToDisplayName(baseDir,
@ -4466,11 +4496,14 @@ def individualPostAsHtml(allowDownloads: bool,
repDisp, repDisp,
False) False)
# benchmark 13.6 # benchmark 13.6
timeDiff = int((time.time() - if not allowDownloads:
postStartTime) * 1000) timeDiff = \
if timeDiff > 100: int((time.time() -
print('TIMING INDIV ' + boxName + postStartTime) * 1000)
' 13.6 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' +
boxName + ' 13.6 = ' +
str(timeDiff))
titleStr += \ titleStr += \
' <img loading="lazy" title="' + \ ' <img loading="lazy" title="' + \
translate['replying to'] + \ translate['replying to'] + \
@ -4483,11 +4516,12 @@ def individualPostAsHtml(allowDownloads: bool,
'">' + replyDisplayName + '</a>\n' '">' + replyDisplayName + '</a>\n'
# benchmark 13.7 # benchmark 13.7
timeDiff = int((time.time() - if not allowDownloads:
postStartTime) * 1000) timeDiff = int((time.time() -
if timeDiff > 100: postStartTime) * 1000)
print('TIMING INDIV ' + boxName + if timeDiff > 100:
' 13.7 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName +
' 13.7 = ' + str(timeDiff))
# show avatar of person replied to # show avatar of person replied to
replyAvatarUrl = \ replyAvatarUrl = \
@ -4497,11 +4531,12 @@ def individualPostAsHtml(allowDownloads: bool,
allowDownloads) allowDownloads)
# benchmark 13.8 # benchmark 13.8
timeDiff = int((time.time() - if not allowDownloads:
postStartTime) * 1000) timeDiff = int((time.time() -
if timeDiff > 100: postStartTime) * 1000)
print('TIMING INDIV ' + boxName + if timeDiff > 100:
' 13.8 = ' + str(timeDiff)) print('TIMING INDIV ' + boxName +
' 13.8 = ' + str(timeDiff))
if replyAvatarUrl: if replyAvatarUrl:
replyAvatarImageInPost = \ replyAvatarImageInPost = \
@ -4570,9 +4605,10 @@ def individualPostAsHtml(allowDownloads: bool,
'">' + postDomain + '</a>\n' '">' + postDomain + '</a>\n'
# benchmark 14 # benchmark 14
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 14 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 14 = ' + str(timeDiff))
attachmentStr, galleryStr = \ attachmentStr, galleryStr = \
getPostAttachmentsAsHtml(postJsonObject, boxName, translate, getPostAttachmentsAsHtml(postJsonObject, boxName, translate,
@ -4598,9 +4634,10 @@ def individualPostAsHtml(allowDownloads: bool,
publishedStr = datetimeObject.strftime("%a %b %d, %H:%M") publishedStr = datetimeObject.strftime("%a %b %d, %H:%M")
# benchmark 15 # benchmark 15
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 15 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 15 = ' + str(timeDiff))
publishedLink = messageId publishedLink = messageId
# blog posts should have no /statuses/ in their link # blog posts should have no /statuses/ in their link
@ -4660,9 +4697,10 @@ def individualPostAsHtml(allowDownloads: bool,
postJsonObject['object']['content']) postJsonObject['object']['content'])
# benchmark 16 # benchmark 16
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 16 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 16 = ' + str(timeDiff))
if not isPatch: if not isPatch:
objectContent = \ objectContent = \
@ -4705,9 +4743,10 @@ def individualPostAsHtml(allowDownloads: bool,
contentStr += cwContentStr contentStr += cwContentStr
# benchmark 17 # benchmark 17
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 17 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 17 = ' + str(timeDiff))
if postJsonObject['object'].get('tag') and not isPatch: if postJsonObject['object'].get('tag') and not isPatch:
contentStr = \ contentStr = \
@ -4738,9 +4777,10 @@ def individualPostAsHtml(allowDownloads: bool,
postHtml = galleryStr postHtml = galleryStr
# benchmark 18 # benchmark 18
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 18 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 18 = ' + str(timeDiff))
if not showPublicOnly and storeToCache and \ if not showPublicOnly and storeToCache and \
boxName != 'tlmedia' and boxName != 'tlbookmarks' and \ boxName != 'tlmedia' and boxName != 'tlbookmarks' and \
@ -4751,9 +4791,10 @@ def individualPostAsHtml(allowDownloads: bool,
postJsonObject, postHtml) postJsonObject, postHtml)
# benchmark 19 # benchmark 19
timeDiff = int((time.time() - postStartTime) * 1000) if not allowDownloads:
if timeDiff > 100: timeDiff = int((time.time() - postStartTime) * 1000)
print('TIMING INDIV ' + boxName + ' 19 = ' + str(timeDiff)) if timeDiff > 100:
print('TIMING INDIV ' + boxName + ' 19 = ' + str(timeDiff))
return postHtml return postHtml