From 24df67a6a2f43877c1a5eab26e3c8f503fc34598 Mon Sep 17 00:00:00 2001 From: jinql Date: Mon, 8 Sep 2025 22:51:15 +0800 Subject: [PATCH] 25.09.08 --- favicon_app/asyncs/__init__.py | 3 --- favicon_app/asyncs/favicon_async.py | 2 +- favicon_app/asyncs/favicon_service_async.py | 10 +--------- favicon_app/models/favicon.py | 2 +- favicon_app/routes/favicon_service.py | 17 ++--------------- favicon_app/utils/file_util.py | 8 ++++---- favicon_app/utils/header.py | 1 - 7 files changed, 9 insertions(+), 34 deletions(-) diff --git a/favicon_app/asyncs/__init__.py b/favicon_app/asyncs/__init__.py index 1abf691..40a96af 100644 --- a/favicon_app/asyncs/__init__.py +++ b/favicon_app/asyncs/__init__.py @@ -1,4 +1 @@ # -*- coding: utf-8 -*- - -from .favicon_async import FaviconAsync -from .favicon_service_async import FaviconServiceAsync diff --git a/favicon_app/asyncs/favicon_async.py b/favicon_app/asyncs/favicon_async.py index 0fb1595..ad76f4c 100644 --- a/favicon_app/asyncs/favicon_async.py +++ b/favicon_app/asyncs/favicon_async.py @@ -97,7 +97,7 @@ class FaviconAsync(favicon.Favicon): 元组(内容, 内容类型) """ global _aiohttp_client - logger.info('发送异步请求: %s', url) + logger.debug('发送异步请求: %s', url) # 初始化aiohttp客户端会话 if _aiohttp_client is None: diff --git a/favicon_app/asyncs/favicon_service_async.py b/favicon_app/asyncs/favicon_service_async.py index bedf87c..18d2e1a 100644 --- a/favicon_app/asyncs/favicon_service_async.py +++ b/favicon_app/asyncs/favicon_service_async.py @@ -27,12 +27,6 @@ class FaviconServiceAsync(favicon_service.FaviconService): icon_content = None try: - if entity.domain in self.domain_list: - self._queue_pull(True, self.total_queue) - return _cached or setting.default_icon_file - else: - self.domain_list.append(entity.domain) - # 尝试从网站异步获取HTML内容 html_content = await entity.async_req_get() if html_content: @@ -60,7 +54,7 @@ class FaviconServiceAsync(favicon_service.FaviconService): strategy_url, strategy_name = strategy() if strategy_url is not None: - logger.info(f"-> 异步尝试从 {strategy_name} 获取图标") + logger.debug(f"-> 异步尝试从 {strategy_name} 获取图标") icon_content, icon_type = await entity.async_get_icon_file(strategy_url, strategy_url == '') # 图标获取失败,或图标不是支持的图片格式,写入默认图标 @@ -90,8 +84,6 @@ class FaviconServiceAsync(favicon_service.FaviconService): logger.error(f"异步获取图标时发生错误 {entity.domain}: {e}") return _cached or setting.default_icon_file finally: - if entity.domain in self.domain_list: - self.domain_list.remove(entity.domain) # 任务完成,从两个队列中移出元素 self._queue_pull(True, self.total_queue) diff --git a/favicon_app/models/favicon.py b/favicon_app/models/favicon.py index e7ce052..034b14c 100644 --- a/favicon_app/models/favicon.py +++ b/favicon_app/models/favicon.py @@ -255,7 +255,7 @@ class Favicon: Returns: 元组(内容, 内容类型) """ - logger.info('发送请求: %s', url) + logger.debug('发送请求: %s', url) retry_count = 0 while retry_count <= retries: diff --git a/favicon_app/routes/favicon_service.py b/favicon_app/routes/favicon_service.py index 1c9e6ef..1993330 100644 --- a/favicon_app/routes/favicon_service.py +++ b/favicon_app/routes/favicon_service.py @@ -40,12 +40,8 @@ class FaviconService: self.url_count = 0 self.request_icon_count = 0 self.request_cache_count = 0 - self.domain_list: List[str] = list() # 初始化队列 - # 实时处理的任务数量 - # self.icon_queue = Queue() - # 所有正在处理的任务数量 self.total_queue = Queue() # # 队列阈值常量配置 @@ -238,7 +234,7 @@ class FaviconService: self._get_link_rel(html_links, entity, '')) if icon_url: - logger.info(f"-> 从HTML获取图标URL: {icon_url}") + logger.debug(f"-> 从HTML获取图标URL: {icon_url}") return icon_url except Exception as e: @@ -270,12 +266,6 @@ class FaviconService: icon_content = None try: - if entity.domain in self.domain_list: - self._queue_pull(True, self.total_queue) - return _cached or setting.default_icon_file - else: - self.domain_list.append(entity.domain) - # 尝试从网站获取HTML内容 html_content = entity.req_get() if html_content: @@ -305,7 +295,7 @@ class FaviconService: strategy_url, strategy_name = strategy() if strategy_url is not None: - logger.info(f"-> 尝试从 {strategy_name} 获取图标") + logger.debug(f"-> 尝试从 {strategy_name} 获取图标") icon_content, icon_type = entity.get_icon_file(strategy_url, strategy_url == '') # 图标获取失败,或图标不是支持的图片格式,写入默认图标 @@ -335,8 +325,6 @@ class FaviconService: logger.error(f"获取图标时发生错误 {entity.domain}: {e}") return _cached or setting.default_icon_file finally: - if entity.domain in self.domain_list: - self.domain_list.remove(entity.domain) # 任务完成,从两个队列中移出元素 self._queue_pull(True, self.total_queue) @@ -347,7 +335,6 @@ class FaviconService: 'request_icon_count': self.request_icon_count, 'request_cache_count': self.request_cache_count, 'queue_size': self.total_queue.qsize(), - 'domain_list': len(self.domain_list), } def get_favicon_handler( diff --git a/favicon_app/utils/file_util.py b/favicon_app/utils/file_util.py index becfd79..9547b3d 100644 --- a/favicon_app/utils/file_util.py +++ b/favicon_app/utils/file_util.py @@ -80,7 +80,7 @@ class FileUtil: if not FileUtil._validate_path(path): return [] - logger.info(f"开始遍历目录: {path}, 递归: {recursive}, 最小文件大小: {min_size}字节") + logger.debug(f"开始遍历目录: {path}, 递归: {recursive}, 最小文件大小: {min_size}字节") result = [] if recursive: @@ -97,7 +97,7 @@ class FileUtil: continue FileUtil._process_file(path, filename, min_size, include_size, result) - logger.info(f"目录遍历完成: {path}, 找到文件数: {len(result)}") + logger.debug(f"目录遍历完成: {path}, 找到文件数: {len(result)}") return result @staticmethod @@ -124,7 +124,7 @@ class FileUtil: if not FileUtil._validate_path(path): return {} - logger.info(f"开始构建文件字典: {path}") + logger.debug(f"开始构建文件字典: {path}") file_dict = {} for root, _, files in os.walk(path): @@ -148,7 +148,7 @@ class FileUtil: if not recursive: break - logger.info(f"文件字典构建完成: {path}, 文件数: {len(file_dict)}") + logger.debug(f"文件字典构建完成: {path}, 文件数: {len(file_dict)}") return file_dict @staticmethod diff --git a/favicon_app/utils/header.py b/favicon_app/utils/header.py index 87834e4..c5bb8cf 100644 --- a/favicon_app/utils/header.py +++ b/favicon_app/utils/header.py @@ -6,7 +6,6 @@ import threading from typing import Dict, Optional # 配置日志 -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__)