Skip to content

Commit

Permalink
fix: 修复一下存储没有权重的问题(特别情况下)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiu2b2t committed Nov 30, 2024
1 parent 3e57f52 commit 47f1cf8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.16
3.0.17
1 change: 1 addition & 0 deletions core/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def get_width_storage(self, c_storage: Optional[storages.iStorage] = None) -> st
current_storage.current_width += 1
return current_storage
else:
current_storage.current_width = 0
self.available_storages.remove(current_storage)
self.available_storages.append(current_storage)
if c_storage is not None:
Expand Down
37 changes: 24 additions & 13 deletions core/storages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,12 @@ def empty():
update_tqdm = update

files: defaultdict[str, deque[File]] = defaultdict(deque)
async with aiohttp.ClientSession(
self.url,
headers={
"Authorization": await self._get_token()
}
) as session:
for root_id in range(0, 256):
root = f"{self.path}/{root_id:02x}"
if f"listfile_{root}" in self.cache:
result = self.cache.get(f"listfile_{root}")
else:
async def get_files(root_id: int):
root = f"{self.path}/{root_id:02x}"
if f"listfile_{root}" in self.cache:
result = self.cache.get(f"listfile_{root}")
else:
try:
async with session.post(
"/api/fs/list",
data={
Expand All @@ -395,8 +390,24 @@ def empty():
if result.code != 200:
logger.tdebug("storage.debug.error_alist", status=result.code, message=result.message)
else:
self.cache.set(f"listfile_{root}", result, 30)
for r in ((result.data or {}).get("content", None) or []):
self.cache.set(f"listfile_{root}", result, 60)
except:
logger.traceback()
return []
return ((result.data or {}).get("content", None) or [])
async with aiohttp.ClientSession(
self.url,
headers={
"Authorization": await self._get_token()
}
) as session:
results = await asyncio.gather(
*(get_files(root_id) for root_id in range(256))
)
for root_id, result in zip(
range(256), results
):
for r in result:
file = File(
r["name"],
r["size"],
Expand Down
5 changes: 4 additions & 1 deletion core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def format_count_datetime(secs: float) -> str:
ms = int(secs * 1000)
s = int(ms / 1000) % 60
m = int(ms / (1000 * 60)) % 60
h = int(ms / (1000 * 60 * 60))
h = int(ms / (1000 * 60 * 60)) % 24
d = int(ms / (1000 * 60 * 60 * 24))
if d > 0:
return f'{d:02d}:{h:02d}:{m:02d}:{s:02d}'
if h > 0:
return f'{h:02d}:{m:02d}:{s:02d}'
else:
Expand Down

0 comments on commit 47f1cf8

Please sign in to comment.