From db3efb4452d7f7eb04bc29049d2a1d2f9e6e7c36 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 4 Aug 2025 08:34:31 +0800 Subject: [PATCH] fix SiteStatistic --- app/db/site_oper.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/db/site_oper.py b/app/db/site_oper.py index a6e0e0b9..9164897d 100644 --- a/app/db/site_oper.py +++ b/app/db/site_oper.py @@ -198,13 +198,17 @@ class SiteOper(DbOper): lst_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") sta = SiteStatistic.get_by_domain(self._db, domain) if sta: - avg_seconds, note = None, sta.note or {} + # 使用深复制确保 note 是全新的字典对象 + note = dict(sta.note) if sta.note else {} + avg_seconds = None + if seconds is not None: note[lst_date] = seconds or 1 avg_times = len(note.keys()) if avg_times > 10: note = dict(sorted(note.items(), key=lambda x: x[0], reverse=True)[:10]) avg_seconds = sum([v for v in note.values()]) // avg_times + sta.update(self._db, { "success": sta.success + 1, "seconds": avg_seconds or sta.seconds, @@ -256,13 +260,17 @@ class SiteOper(DbOper): lst_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") sta = await SiteStatistic.async_get_by_domain(self._db, domain) if sta: - avg_seconds, note = None, sta.note or {} + # 使用深复制确保 note 是全新的字典对象 + note = dict(sta.note) if sta.note else {} + avg_seconds = None + if seconds is not None: note[lst_date] = seconds or 1 avg_times = len(note.keys()) if avg_times > 10: note = dict(sorted(note.items(), key=lambda x: x[0], reverse=True)[:10]) avg_seconds = sum([v for v in note.values()]) // avg_times + await sta.async_update(self._db, { "success": sta.success + 1, "seconds": avg_seconds or sta.seconds,