Check before adding new entries to indexes

merge-requests/8/head
Bob Mottram 2020-12-29 20:22:28 +00:00
parent cce7941b39
commit adbddb95c3
8 changed files with 34 additions and 23 deletions

View File

@ -204,10 +204,11 @@ def updateBookmarksCollection(recentPostsCache: {},
try:
with open(bookmarksIndexFilename, 'r+') as bmIndexFile:
content = bmIndexFile.read()
bmIndexFile.seek(0, 0)
bmIndexFile.write(bookmarkIndex + '\n' + content)
if debug:
print('DEBUG: bookmark added to index')
if bookmarkIndex + '\n' not in content:
bmIndexFile.seek(0, 0)
bmIndexFile.write(bookmarkIndex + '\n' + content)
if debug:
print('DEBUG: bookmark added to index')
except Exception as e:
print('WARN: Failed to write entry to bookmarks index ' +
bookmarksIndexFilename + ' ' + str(e))

View File

@ -725,8 +725,10 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
try:
with open(followersFilename, 'r+') as followersFile:
content = followersFile.read()
followersFile.seek(0, 0)
followersFile.write(approveHandle + '\n' + content)
if approveHandle + '\n' not in content:
followersFile.seek(0, 0)
followersFile.write(approveHandle + '\n' +
content)
except Exception as e:
print('WARN: ' +
'Failed to write entry to followers file ' +

View File

@ -96,8 +96,9 @@ def saveEventPost(baseDir: str, handle: str, postId: str,
try:
with open(tlEventsFilename, 'r+') as tlEventsFile:
content = tlEventsFile.read()
tlEventsFile.seek(0, 0)
tlEventsFile.write(eventId + '\n' + content)
if eventId + '\n' not in content:
tlEventsFile.seek(0, 0)
tlEventsFile.write(eventId + '\n' + content)
except Exception as e:
print('WARN: Failed to write entry to events file ' +
tlEventsFilename + ' ' + str(e))

View File

@ -123,8 +123,9 @@ def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
try:
with open(tagsFilename, 'r+') as tagsFile:
content = tagsFile.read()
tagsFile.seek(0, 0)
tagsFile.write(tagline + content)
if tagline not in content:
tagsFile.seek(0, 0)
tagsFile.write(tagline + content)
except Exception as e:
print('WARN: Failed to write entry to tags file ' +
tagsFilename + ' ' + str(e))

View File

@ -184,8 +184,10 @@ def manualApproveFollowRequest(session, baseDir: str,
try:
with open(followersFilename, 'r+') as followersFile:
content = followersFile.read()
followersFile.seek(0, 0)
followersFile.write(approveHandleFull + '\n' + content)
if approveHandleFull + '\n' not in content:
followersFile.seek(0, 0)
followersFile.write(approveHandleFull + '\n' +
content)
except Exception as e:
print('WARN: Manual follow accept. ' +
'Failed to write entry to followers file ' + str(e))

View File

@ -46,9 +46,10 @@ def _updateFeedsOutboxIndex(baseDir: str, domain: str, postId: str) -> None:
try:
with open(indexFilename, 'r+') as feedsFile:
content = feedsFile.read()
feedsFile.seek(0, 0)
feedsFile.write(postId + '\n' + content)
print('DEBUG: feeds post added to index')
if postId + '\n' not in content:
feedsFile.seek(0, 0)
feedsFile.write(postId + '\n' + content)
print('DEBUG: feeds post added to index')
except Exception as e:
print('WARN: Failed to write entry to feeds posts index ' +
indexFilename + ' ' + str(e))

View File

@ -668,8 +668,9 @@ def _updateHashtagsIndex(baseDir: str, tag: {}, newPostId: str) -> None:
try:
with open(tagsFilename, 'r+') as tagsFile:
content = tagsFile.read()
tagsFile.seek(0, 0)
tagsFile.write(tagline+content)
if tagline not in content:
tagsFile.seek(0, 0)
tagsFile.write(tagline + content)
except Exception as e:
print('WARN: Failed to write entry to tags file ' +
tagsFilename + ' ' + str(e))
@ -688,9 +689,10 @@ def _addSchedulePost(baseDir: str, nickname: str, domain: str,
try:
with open(scheduleIndexFilename, 'r+') as scheduleFile:
content = scheduleFile.read()
scheduleFile.seek(0, 0)
scheduleFile.write(indexStr + '\n' + content)
print('DEBUG: scheduled post added to index')
if indexStr + '\n' not in content:
scheduleFile.seek(0, 0)
scheduleFile.write(indexStr + '\n' + content)
print('DEBUG: scheduled post added to index')
except Exception as e:
print('WARN: Failed to write entry to scheduled posts index ' +
scheduleIndexFilename + ' ' + str(e))

View File

@ -708,9 +708,10 @@ def followPerson(baseDir: str, nickname: str, domain: str,
try:
with open(filename, 'r+') as f:
content = f.read()
f.seek(0, 0)
f.write(handleToFollow + '\n' + content)
print('DEBUG: follow added')
if handleToFollow + '\n' not in content:
f.seek(0, 0)
f.write(handleToFollow + '\n' + content)
print('DEBUG: follow added')
except Exception as e:
print('WARN: Failed to write entry to follow file ' +
filename + ' ' + str(e))