From e7da187e181ace94825c35d027f003ffc35a9986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20M=C3=A4gi?= Date: Fri, 22 Sep 2023 16:48:41 +0300 Subject: [PATCH] Add TTL index --- camdetect.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/camdetect.py b/camdetect.py index 1865b10..b571235 100755 --- a/camdetect.py +++ b/camdetect.py @@ -56,6 +56,9 @@ CLOCK_SKEW_TOLERANCE = timedelta(seconds=3) # Percentage of blocks active to consider movement in whole frame THRESHOLD_RATIO = int(os.getenv("THRESHOLD_RATIO", "5")) +# Days to keep events +TTL_DAYS = int(os.getenv("TTL_DAYS", "3")) + CHUNK_BOUNDARY = b"\n--frame\nContent-Type: image/jpeg\n\n" hist_active_blocks_ratio = Histogram( @@ -560,6 +563,8 @@ async def setup_db(app, loop): app.ctx.coll.create_index([ ("source", pymongo.ASCENDING), ("@timestamp", pymongo.ASCENDING)], unique=True) + app.ctx.coll.create_index( + "@timestamp", expireAfterSeconds=TTL_DAYS*60*60*24) app.ctx.last_frame = None app.ctx.event_frame = asyncio.Event() app.ctx.event_id = None