From ebf2f53ae190517149ba563a4e87687a0f5dddd0 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 19 Apr 2024 19:51:01 +0800 Subject: [PATCH] fix api --- app/api/endpoints/douban.py | 2 +- app/db/sytestatistic_oper.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/api/endpoints/douban.py b/app/api/endpoints/douban.py index d4981f58..2bcd2e75 100644 --- a/app/api/endpoints/douban.py +++ b/app/api/endpoints/douban.py @@ -13,7 +13,7 @@ from app.utils.http import RequestUtils router = APIRouter() -@router.get("/img/{imgurl:path}", summary="豆瓣图片代理") +@router.get("/img", summary="豆瓣图片代理") def douban_img(imgurl: str) -> Any: """ 豆瓣图片代理 diff --git a/app/db/sytestatistic_oper.py b/app/db/sytestatistic_oper.py index 202d516f..348fbd1f 100644 --- a/app/db/sytestatistic_oper.py +++ b/app/db/sytestatistic_oper.py @@ -18,10 +18,12 @@ class SiteStatisticOper(DbOper): sta = SiteStatistic.get_by_domain(self._db, domain) if sta: avg_seconds, note = None, {} - if seconds: + if seconds is not None: note: dict = json.loads(sta.note or "{}") - note[lst_date] = seconds + 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, @@ -32,15 +34,15 @@ class SiteStatisticOper(DbOper): }) else: note = {} - if seconds: + if seconds is not None: note = { - lst_date: seconds + lst_date: seconds or 1 } SiteStatistic( domain=domain, success=1, fail=0, - seconds=seconds, + seconds=seconds or 1, lst_state=0, lst_mod_date=lst_date, note=json.dumps(note)