Compare commits

..

2 commits

Author SHA1 Message Date
6f80bbc0be Merge pull request 'Discount any history times older than 6 months' (#36) from limit-history into main
Some checks failed
Test, Build and Publish / build-and-push-images (push) Blocked by required conditions
Test, Build and Publish / test (push) Has been cancelled
Reviewed-on: #36
2025-11-29 23:15:07 +00:00
3675430390 Discount any history times older than 6 months
All checks were successful
Test, Build and Publish / test (pull_request) Successful in 37s
Test, Build and Publish / build-and-push-images (pull_request) Successful in 44s
2025-11-29 23:13:03 +00:00

View file

@ -1,6 +1,6 @@
"""Store bot state"""
import os
from datetime import datetime
from datetime import datetime, timedelta
from schema import Schema, Use, Optional
from collections.abc import Generator
from typing import Protocol
@ -243,18 +243,20 @@ class _State():
def get_history_timestamps(self, users: list[Member]) -> list[datetime]:
"""Grab all timestamps in the history"""
others = [m.id for m in users]
ids = [int(m.id) for m in users]
# Fetch all the interaction times in history
# But only for interactions in the given user group
times = set()
for data in (data for id, data in self._users.items() if int(id) in others):
for data in (data for id, data in self._users.items() if id in ids):
matches = data.get(_Key.MATCHES, {})
for ts in (ts for id, ts in matches.items() if int(id) in others):
for ts in (ts for id, ts in matches.items() if id in ids):
times.add(ts)
# Convert to datetimes and sort
datetimes = [ts_to_datetime(ts) for ts in times]
# Remove any entries older than 6 months ago
datetimes = [t for t in datetimes if t >= datetime.now() - timedelta(months=3)]
datetimes.sort()
return datetimes