Skip to content

Commit

Permalink
Merge pull request #60 from TTB-Network/dev/master
Browse files Browse the repository at this point in the history
回滚一些代码
  • Loading branch information
tianxiu2b2t authored May 2, 2024
2 parents 0080f03 + 0f1df03 commit cb4a8dc
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions core/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def __init__(self, name: str, dir: Path, width: int) -> None:
if self.dir.is_file():
raise FileExistsError(f"Cannot copy file: '{self.dir}': Is a file.")
self.dir.mkdir(exist_ok=True, parents=True)
self.cache: CacheManager = CacheManager(FileType.LOCAL, FileContentType.DATA if CACHE_ENABLE else FileContentType.PATH)
self.cache: dict[str, File] = {}
self.timer = scheduler.repeat(
self.clear_cache, delay=CHECK_CACHE, interval=CHECK_CACHE
)
Expand Down Expand Up @@ -902,7 +902,7 @@ async def write(self, hash: str, io: io.BytesIO) -> int:
path = self._file_endpoint(f"{hash[:2]}/{hash}")
await self._mkdir(self._file_endpoint(f"{hash[:2]}"))
await self._execute(self.session.upload_to(io.getbuffer(), path))
self.files[hash] = File(path, hash, len(io.getbuffer()))
self.files[hash] = File(path, hash, len(io.getbuffer()), FileContentType.URL)
return self.files[hash].size

async def get_files(self, dir: str) -> list[str]:
Expand Down Expand Up @@ -1341,27 +1341,10 @@ async def message(self, channel, data: list[Any], callback=None):
logger.error(traceback.format_exc())


class CacheManager:
def __init__(self, type: FileType, data: FileContentType):
self.type = type
self.data = data
self.cache: dict[str, File] = {}

def set(self, key: str, value: File) -> File:
self.cache[key] = value
return value

def get_or_default(self, key: str) -> Optional[File]:
if key not in self.cache:
return None
return self.cache[key]


token = TokenManager()
cluster: Optional[Cluster] = None
last_status: str = "-"
storages = StorageManager()
cache: CacheManager = CacheManager()


async def init():
Expand Down

0 comments on commit cb4a8dc

Please sign in to comment.