From f94f6eb997e3fec2fc3dc6828405f5dc5f17ce5b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 13 Dec 2020 14:31:22 +0000 Subject: [PATCH] Don't write time to file if it hasn't changed --- inbox.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inbox.py b/inbox.py index 5a86bfb71..0489aff7a 100644 --- a/inbox.py +++ b/inbox.py @@ -2088,6 +2088,13 @@ def updateLastSeen(baseDir: str, handle: str, actor: str) -> None: lastSeenFilename = lastSeenPath + '/' + actor.replace('/', '#') + '.txt' currTime = datetime.datetime.utcnow() daysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days + # has the value changed? + if os.path.isfile(lastSeenFilename): + with open(lastSeenFilename, 'r') as lastSeenFile: + daysSinceEpochFile = lastSeenFile.read() + if int(daysSinceEpochFile) == daysSinceEpoch: + # value hasn't changed, so we can save writing anything to file + return with open(lastSeenFilename, 'w+') as lastSeenFile: lastSeenFile.write(str(daysSinceEpoch))