🐛 修复下载历史重复计数
This commit is contained in:
+17
-2
@@ -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}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user