Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/fuse.py
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | async def get_blob(self, swhid: SWHID) -> bytes: | ||||
resp = await loop.run_in_executor(None, self.web_api.content_raw, swhid) | resp = await loop.run_in_executor(None, self.web_api.content_raw, swhid) | ||||
blob = b"".join(list(resp)) | blob = b"".join(list(resp)) | ||||
await self.cache.blob.set(swhid, blob) | await self.cache.blob.set(swhid, blob) | ||||
return blob | return blob | ||||
except requests.HTTPError as err: | except requests.HTTPError as err: | ||||
self.logger.error("Cannot fetch blob for object %s: %s", swhid, err) | self.logger.error("Cannot fetch blob for object %s: %s", swhid, err) | ||||
raise | raise | ||||
async def get_history(self, swhid: SWHID) -> List[SWHID]: | # async def get_history(self, swhid: SWHID) -> List[SWHID]: | ||||
""" Retrieve a revision's history using Software Heritage Graph API """ | # """ Retrieve a revision's history using Software Heritage Graph API """ | ||||
if swhid.object_type != REVISION: | # if swhid.object_type != REVISION: | ||||
raise pyfuse3.FUSEError(errno.EINVAL) | # raise pyfuse3.FUSEError(errno.EINVAL) | ||||
cache = await self.cache.history.get(swhid) | |||||
if cache: | |||||
self.logger.debug( | |||||
"Found history of %s in cache (%d ancestors)", swhid, len(cache) | |||||
) | |||||
return cache | |||||
try: | # cache = await self.cache.history.get(swhid) | ||||
# Use the swh-graph API to retrieve the full history very fast | # if cache: | ||||
self.logger.debug("Retrieving history of %s via graph API...", swhid) | # self.logger.debug( | ||||
call = f"graph/visit/edges/{swhid}?edges=rev:rev" | # "Found history of %s in cache (%d ancestors)", swhid, len(cache) | ||||
loop = asyncio.get_event_loop() | # ) | ||||
history = await loop.run_in_executor(None, self.web_api._call, call) | # return cache | ||||
await self.cache.history.set(history.text) | |||||
# Retrieve it from cache so it is correctly typed | # try: | ||||
res = await self.cache.history.get(swhid) | # # Use the swh-graph API to retrieve the full history very fast | ||||
return res | # self.logger.debug("Retrieving history of %s via graph API...", swhid) | ||||
except requests.HTTPError as err: | # call = f"graph/visit/edges/{swhid}?edges=rev:rev" | ||||
self.logger.error("Cannot fetch history for object %s: %s", swhid, err) | # loop = asyncio.get_event_loop() | ||||
# Ignore exception since swh-graph does not necessarily contain the | # history = await loop.run_in_executor(None, self.web_api._call, call) | ||||
# most recent artifacts from the archive. Computing the full history | # await self.cache.history.set(history.text) | ||||
# from the Web API is too computationally intensive so simply return | # # Retrieve it from cache so it is correctly typed | ||||
# an empty list. | # res = await self.cache.history.get(swhid) | ||||
return [] | # return res | ||||
# except requests.HTTPError as err: | |||||
# self.logger.error("Cannot fetch history for object %s: %s", swhid, err) | |||||
# # Ignore exception since swh-graph does not necessarily contain the | |||||
# # most recent artifacts from the archive. Computing the full history | |||||
# # from the Web API is too computationally intensive so simply return | |||||
# # an empty list. | |||||
# return [] | |||||
async def get_visits(self, url_encoded: str) -> List[Dict[str, Any]]: | async def get_visits(self, url_encoded: str) -> List[Dict[str, Any]]: | ||||
""" Retrieve origin visits given an encoded-URL using Software Heritage API """ | """ Retrieve origin visits given an encoded-URL using Software Heritage API """ | ||||
cache = await self.cache.metadata.get_visits(url_encoded) | cache = await self.cache.metadata.get_visits(url_encoded) | ||||
if cache: | if cache: | ||||
self.logger.debug( | self.logger.debug( | ||||
"Found %d visits for origin '%s' in cache", len(cache), url_encoded, | "Found %d visits for origin '%s' in cache", len(cache), url_encoded, | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |