Calculate the min stats date with timedelta

This is more correct than just using days.
I've also tested this working in a completely separate Peewee project.
This commit is contained in:
luukas 2022-05-25 16:14:42 +03:00
parent a937a94ac8
commit 83018c6860
No known key found for this signature in database
GPG Key ID: CC4915E8D71FC044
2 changed files with 2 additions and 2 deletions

View File

@ -258,6 +258,6 @@ class Stats:
# delete old data
max_age = self.helper.get_setting("history_max_age")
now = datetime.datetime.now()
minimum_to_exist = now.day - max_age
minimum_to_exist = now - datetime.timedelta(days=max_age)
HostStats.delete().where(HostStats.time < minimum_to_exist).execute()

View File

@ -1450,6 +1450,6 @@ class Server:
# delete old data
max_age = self.helper.get_setting("history_max_age")
now = datetime.datetime.now()
minimum_to_exist = now.day - max_age
minimum_to_exist = now - datetime.timedelta(days=max_age)
HelperServerStats.remove_old_stats(server.get("id", 0), minimum_to_exist)