This commit is contained in:
jinql
2025-09-06 12:45:58 +08:00
parent 2a4f5867b4
commit 5972366cae
2 changed files with 37 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ from bs4 import SoupStrainer
from fastapi import Request, BackgroundTasks
from fastapi.responses import Response
from favicon_app.models import Favicon
from favicon_app.models import Favicon, favicon
from favicon_app.utils import header
from favicon_app.utils.file_util import FileUtil
from favicon_app.utils.filetype import helpers, filetype
@@ -368,6 +368,9 @@ class FaviconService:
sync: Optional[str] = None
) -> dict[str, str] | Response:
"""处理获取图标的请求"""
logger.info(f"队列大小:{self.icon_queue.qsize()} | {self.total_queue.qsize()}")
with self._lock:
self.url_count += 1
@@ -383,6 +386,15 @@ class FaviconService:
logger.warning(f"无效的URL: {url}")
return self.get_default(self.time_of_7_days)
# 检查内存缓存中的失败URL
with self._lock:
if entity.domain in favicon.failed_urls:
_expire_time = favicon.failed_urls[entity.domain]
if int(time.time()) <= _expire_time:
return self.get_default(self.time_of_7_days)
else:
del favicon.failed_urls[entity.domain]
# 检查缓存
_cached, cached_icon = self._get_cache_icon(entity.domain_md5, refresh=refresh in ['true', '1', 'True'])