Set event thumbnail cache timeout to 1 day (#3150)

* Set event thumbnail cache timeout to 1 day

* Pass max age as a param and set default to 30 days
This commit is contained in:
Nicolas Mowen 2022-04-26 18:42:07 -06:00 committed by GitHub
parent 5b71271b3c
commit 0bd3cff13b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -274,7 +274,7 @@ def delete_event(id):
@bp.route("/events/<id>/thumbnail.jpg") @bp.route("/events/<id>/thumbnail.jpg")
def event_thumbnail(id): def event_thumbnail(id, max_cache_age=2592000):
format = request.args.get("format", "ios") format = request.args.get("format", "ios")
thumbnail_bytes = None thumbnail_bytes = None
event_complete = False event_complete = False
@ -317,7 +317,7 @@ def event_thumbnail(id):
response = make_response(thumbnail_bytes) response = make_response(thumbnail_bytes)
response.headers["Content-Type"] = "image/jpeg" response.headers["Content-Type"] = "image/jpeg"
if event_complete: if event_complete:
response.headers["Cache-Control"] = "private, max-age=31536000" response.headers["Cache-Control"] = f"private, max-age={max_cache_age}"
else: else:
response.headers["Cache-Control"] = "no-store" response.headers["Cache-Control"] = "no-store"
return response return response
@ -345,7 +345,7 @@ def label_thumbnail(camera_name, label):
try: try:
event = event_query.get() event = event_query.get()
return event_thumbnail(event.id) return event_thumbnail(event.id, 60)
except DoesNotExist: except DoesNotExist:
frame = np.zeros((175, 175, 3), np.uint8) frame = np.zeros((175, 175, 3), np.uint8)
ret, jpg = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70]) ret, jpg = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])