Move history data to a textfile, improves memory handling (#638)

This commit is contained in:
dgtlmoon
2022-05-31 23:43:50 +02:00
committed by GitHub
parent dbb5468cdc
commit aa3c8a9370
14 changed files with 330 additions and 158 deletions

View File

@@ -28,8 +28,7 @@ class Watch(Resource):
return "OK", 200
# Return without history, get that via another API call
watch['history_n'] = len(watch['history'])
del (watch['history'])
watch['history_n'] = watch.history_n
return watch
@auth.check_token
@@ -52,7 +51,7 @@ class WatchHistory(Resource):
watch = self.datastore.data['watching'].get(uuid)
if not watch:
abort(404, message='No watch exists with the UUID of {}'.format(uuid))
return watch['history'], 200
return watch.history, 200
class WatchSingleHistory(Resource):
@@ -69,13 +68,13 @@ class WatchSingleHistory(Resource):
if not watch:
abort(404, message='No watch exists with the UUID of {}'.format(uuid))
if not len(watch['history']):
if not len(watch.history):
abort(404, message='Watch found but no history exists for the UUID {}'.format(uuid))
if timestamp == 'latest':
timestamp = list(watch['history'].keys())[-1]
timestamp = list(watch.history.keys())[-1]
with open(watch['history'][timestamp], 'r') as f:
with open(watch.history[timestamp], 'r') as f:
content = f.read()
response = make_response(content, 200)