🐛 修复下载历史重复计数

This commit is contained in:
2026-06-05 16:34:07 +08:00
parent 87d8f522a6
commit 85af153b38
3 changed files with 37 additions and 7 deletions
+17 -2
View File
@@ -189,10 +189,25 @@ async def analytics(start: str = "", end: str = ""):
end_day = parse_day(end, now.replace(hour=0, minute=0, second=0, microsecond=0))
start_day = parse_day(start, end_day - datetime.timedelta(days=29))
end_exclusive = end_day + datetime.timedelta(days=1)
stats = await TransferStats.filter(
raw_stats = await TransferStats.filter(
created_at__gte=start_day,
created_at__lt=end_exclusive,
)
).order_by("created_at", "id")
stats = []
recent_downloads = {}
for item in raw_stats:
if item.action == "download":
dedupe_key = (
item.file_code_id or item.code or "",
item.ip or "",
int(item.size or 0),
)
previous = recent_downloads.get(dedupe_key)
if previous and (item.created_at - previous).total_seconds() <= 5:
continue
recent_downloads[dedupe_key] = item.created_at
stats.append(item)
files = await FileCodes.all()
file_map = {item.code: item for item in files}