Don't load posts twice

main
Bob Mottram 2019-11-18 11:55:27 +00:00
parent 4401c48682
commit 4b1013cd45
1 changed files with 7 additions and 17 deletions

View File

@ -2276,7 +2276,7 @@ def createBoxBase(session,baseDir: str,boxname: str, \
return boxHeader return boxHeader
return boxItems return boxItems
def isTimelinePost(filePath: str,boxname: str) -> bool: def isTimelinePost(filePath: str,boxname: str,postsInBox: []) -> bool:
""" is this a valid timeline post? """ is this a valid timeline post?
""" """
# must be a "Note" or "Announce" type # must be a "Note" or "Announce" type
@ -2295,6 +2295,8 @@ def isTimelinePost(filePath: str,boxname: str) -> bool:
if '"Create"' in postStr: if '"Create"' in postStr:
if 'mediaType' not in postStr or 'image/' not in postStr: if 'mediaType' not in postStr or 'image/' not in postStr:
return False return False
# add the post to the dictionary
postsInBox.append(filePath)
return True return True
return False return False
@ -2382,16 +2384,10 @@ def createBoxIndexed(session,baseDir: str,boxname: str, \
fullPostFilename= \ fullPostFilename= \
locatePost(baseDir,nickname,domain,postUrl,False) locatePost(baseDir,nickname,domain,postUrl,False)
if fullPostFilename: if fullPostFilename:
if not isTimelinePost(fullPostFilename,boxname): if not isTimelinePost(fullPostFilename,boxnamem,postsInBox):
continue continue
# add the post to the dictionary
postsInBox.append(fullPostFilename)
postsCtr+=1 postsCtr+=1
# number of posts in box
boxHeader['totalItems']=len(postsInBox)
prevPostFilename=None
# Generate first and last entries within header # Generate first and last entries within header
if postsCtr>0: if postsCtr>0:
lastPage=int(postsCtr/itemsPerPage) lastPage=int(postsCtr/itemsPerPage)
@ -2401,25 +2397,19 @@ def createBoxIndexed(session,baseDir: str,boxname: str, \
httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page='+str(lastPage) httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page='+str(lastPage)
if headerOnly: if headerOnly:
boxHeader['totalItems']=len(postsInBox)
prevPageStr='true' prevPageStr='true'
if pageNumber>1: if pageNumber>1:
prevPageStr=str(pageNumber-1) prevPageStr=str(pageNumber-1)
boxHeader['prev']= \ boxHeader['prev']= \
httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page='+prevPageStr httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page='+prevPageStr
nextPageStr='true'
if pageNumber>1:
nextPageStr=str(pageNumber+1) nextPageStr=str(pageNumber+1)
boxHeader['next']= \ boxHeader['next']= \
httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page='+nextPageStr httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page='+nextPageStr
return boxHeader return boxHeader
for postFilename in postsInBox: for postStr in postsInBox:
if not os.path.isfile(postFilename):
continue
# get the full path of the post file
filePath = postFilename
p=None p=None
try: try:
p=json.loads(postStr) p=json.loads(postStr)