Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/fs/artifact.py
Show First 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | class StatusFile(FuseFileEntry): | ||||
todo: int | todo: int | ||||
async def get_content(self) -> bytes: | async def get_content(self) -> bytes: | ||||
fmt = f"Done: {self.done}/{self.todo}\n" | fmt = f"Done: {self.done}/{self.todo}\n" | ||||
return fmt.encode() | return fmt.encode() | ||||
async def compute_entries(self) -> AsyncIterator[FuseEntry]: | async def compute_entries(self) -> AsyncIterator[FuseEntry]: | ||||
history = await self.fuse.get_history(self.history_swhid) | history = await self.fuse.get_history(self.history_swhid) | ||||
# Only check for cached revisions since fetching all of them with the | # Only check for cached revisions with the appropriate prefix, since | ||||
# Web API would take too long | # fetching all of them with the Web API would take too long | ||||
swhids = await self.fuse.cache.metadata.get_cached_subset(history) | swhids = await self.fuse.cache.history.get_with_date_prefix( | ||||
self.history_swhid, date_prefix=self.prefix | |||||
) | |||||
depth = self.prefix.count("/") | depth = self.prefix.count("/") | ||||
root_path = self.get_relative_root_path() | root_path = self.get_relative_root_path() | ||||
sharded_dirs = set() | sharded_dirs = set() | ||||
for swhid in swhids: | for (swhid, sharded_name) in swhids: | ||||
meta = await self.fuse.cache.metadata.get(swhid) | |||||
date = meta["date"] | |||||
sharded_name = self.DATE_FMT.format( | |||||
year=date.year, month=date.month, day=date.day | |||||
) | |||||
if not sharded_name.startswith(self.prefix): | if not sharded_name.startswith(self.prefix): | ||||
continue | continue | ||||
if depth == 3: | if depth == 3: | ||||
yield self.create_child( | yield self.create_child( | ||||
FuseSymlinkEntry, | FuseSymlinkEntry, | ||||
name=str(swhid), | name=str(swhid), | ||||
target=Path(root_path, f"archive/{swhid}"), | target=Path(root_path, f"archive/{swhid}"), | ||||
) | ) | ||||
# Create sharded directories | # Create sharded directories | ||||
else: | else: | ||||
next_prefix = sharded_name.split("/")[depth] | next_prefix = sharded_name.split("/")[depth] | ||||
if next_prefix not in sharded_dirs: | if next_prefix not in sharded_dirs: | ||||
sharded_dirs.add(next_prefix) | sharded_dirs.add(next_prefix) | ||||
yield self.create_child( | yield self.create_child( | ||||
RevisionHistoryShardByDate, | RevisionHistoryShardByDate, | ||||
name=next_prefix, | name=next_prefix, | ||||
mode=int(EntryMode.RDONLY_DIR), | mode=int(EntryMode.RDONLY_DIR), | ||||
prefix=f"{self.prefix}{next_prefix}/", | prefix=f"{self.prefix}{next_prefix}/", | ||||
history_swhid=self.history_swhid, | history_swhid=self.history_swhid, | ||||
) | ) | ||||
# TODO: store len(history) somewhere to avoid recompute? | |||||
self.is_status_done = len(swhids) == len(history) | self.is_status_done = len(swhids) == len(history) | ||||
if not self.is_status_done and depth == 0: | if not self.is_status_done and depth == 0: | ||||
yield self.create_child( | yield self.create_child( | ||||
RevisionHistoryShardByDate.StatusFile, | RevisionHistoryShardByDate.StatusFile, | ||||
done=len(swhids), | done=len(swhids), | ||||
todo=len(history), | todo=len(history), | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |