From 0e87344ee7d84b2cffc03d6af5d86780cfea6678 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 15 Apr 2020 10:12:49 +0100 Subject: [PATCH] Read tag files line by line This prevents the whole file needing to be read and so should improve performance --- webinterface.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/webinterface.py b/webinterface.py index 3fbe7eec..8fb25db1 100644 --- a/webinterface.py +++ b/webinterface.py @@ -5541,12 +5541,13 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str: if daysSinceEpochStr not in open(tagsFilename).read(): continue with open(tagsFilename, 'r') as tagsFile: + line = tagsFile.readline() + lineCtr = 1 tagCtr = 0 - lines = tagsFile.readlines() - for l in lines: - if ' ' not in l: + while line: + if ' ' not in line: continue - postDaysSinceEpochStr = l.split(' ')[0] + postDaysSinceEpochStr = line.split(' ')[0] if not postDaysSinceEpochStr.isdigit(): continue postDaysSinceEpoch = int(postDaysSinceEpochStr) @@ -5558,6 +5559,13 @@ def htmlHashTagSwarm(baseDir: str, actor: str) -> str: tagCtr += 1 if tagCtr > 3: break + + line = tagsFile.readline() + lineCtr += 1 + # don't read too many lines + if lineCtr > 4: + break + if tagCtr > 0: tagSwarmCtr.append(tagCtr) if not tagSwarm: