Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/cache.py
Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | class MetadataCache(AbstractCache): | ||||
async def set(self, swhid: SWHID, metadata: Any) -> None: | async def set(self, swhid: SWHID, metadata: Any) -> None: | ||||
await self.conn.execute( | await self.conn.execute( | ||||
"insert into metadata_cache values (?, ?)", | "insert into metadata_cache values (?, ?)", | ||||
(str(swhid), json.dumps(metadata)), | (str(swhid), json.dumps(metadata)), | ||||
) | ) | ||||
await self.conn.commit() | await self.conn.commit() | ||||
async def get_cached_subset(self, swhids: List[SWHID]) -> List[SWHID]: | |||||
swhids_str = ",".join(f'"{x}"' for x in swhids) | |||||
cursor = await self.conn.execute( | |||||
f"select swhid from metadata_cache where swhid in ({swhids_str})" | |||||
) | |||||
cache = await cursor.fetchall() | |||||
res = [] | |||||
for swhid in cache: | |||||
seirl: Use row/swhid to avoid reusing a variable name with a different type | |||||
swhid = swhid[0] | |||||
try: | |||||
res.append(parse_swhid(swhid)) | |||||
except ValidationError: | |||||
logging.warning("Cannot parse object from metadata cache: %s", swhid) | |||||
return res | |||||
class BlobCache(AbstractCache): | class BlobCache(AbstractCache): | ||||
""" The blob cache map SWHIDs of type `cnt` to the bytes of their archived | """ The blob cache map SWHIDs of type `cnt` to the bytes of their archived | ||||
content. | content. | ||||
The blob cache entry for a given content object is populated, at the latest, | The blob cache entry for a given content object is populated, at the latest, | ||||
the first time the object is `read()`-d. It might be populated earlier on | the first time the object is `read()`-d. It might be populated earlier on | ||||
due to prefetching, e.g., when a directory pointing to the given content is | due to prefetching, e.g., when a directory pointing to the given content is | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |
Use row/swhid to avoid reusing a variable name with a different type