10BC0 chore: 优化 0 bytes 文件 · TTB-Network/python-openbmclapi@fbba33a · GitHub
[go: up one dir, main page]

Skip to content

Commit fbba33a

Browse files
committed
chore: 优化 0 bytes 文件
1 parent c50b6d5 commit fbba33a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

core/cluster.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ async def refresh_token(self):
100100
async with aiohttp.ClientSession(
101101
base_url=cfg.base_url,
102102
headers={
103+
"Authorization": f"Bearer {self._token}",
103104
"User-Agent": USER_AGENT,
104105
}
105106
) as session:
@@ -592,6 +593,8 @@ def __init__(
592593
self._task_group = None
593594
self._certificate_type: Optional[CertificateType] = None
594595
self._cluster_name = False
596+
self._zero_bytes_files: set[BMCLAPIFile] = set()
597+
self._zero_bytes_hash: set[str] = set()
595598

596599
def add_cluster(
597600
self,
@@ -640,12 +643,18 @@ async def _(msg: Any):
640643

641644
async def get_files(self) -> set[BMCLAPIFile]:
642645
# 批量获取 files
643-
return set().union(
646+
files = set().union(
644647
*await concurrency.gather(*[
645648
cluster.get_files() for cluster in self.clusters
646649
])
647650
)
648651

652+
# filter 0 bytes
653+
zero_bytes = set(filter(lambda x: x.size == 0, files))
654+
self._zero_bytes_files = zero_bytes
655+
self._zero_bytes_hash = set([f.hash for f in zero_bytes])
656+
return files - zero_bytes
657+
649658
async def sync(self):
650659
assert self._task_group is not None
651660

@@ -713,6 +722,10 @@ def hit(self, cluster_id: str, bytes: int):
713722
self._clusters[cluster_id].counter.bytes += bytes
714723

715724
async def get_response_file(self, hash: str) -> ResponseFile:
725+
if hash in self._zero_bytes_hash:
726+
return ResponseFile(
727+
0
728+
)
716729
storage = self.storages.get_weight_storage()
717730
if storage is None:
718731
logger.twarning("cluster.get_response_file.no_storage")

locale/zh_cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"info.cluster.want_enable": "节点 [${name} (${id})] 上线",
3030
"info.core.exit": "已退出",
3131
"info.core.initialize": "初始化中...",
32-
"info.core.initialize.cluster": "加载节点 [${name} (${id})]",
32+
"info.core.initialize.cluster": "加载节点 [${id}]",
3333
"info.core.initialize.platform": "操作平台 [${os} ${arch}] Python 版本 [${python}]",
3434
"info.core.initialize.storage": "加载存储 [${name} (${type})]",
3535
"info.core.initialize.version": "API 版本: [${api_version}] Python OpenBMCLAPI 版本 [${version}]",

0 commit comments

Comments
 (0)
0