Skip to content

Commit

Permalink
Merge pull request #45 from astropy/no_async
Browse files Browse the repository at this point in the history
further algolia API compatability
  • Loading branch information
adrn authored Oct 29, 2024
2 parents a0bb8e8 + 06f6628 commit d3bfc80
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions astropylibrarian/algolia/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ async def __aexit__(
await self.algolia_client.close()
self._logger.debug("Finished closing algolia client")

async def browse_objects_async(
async def browse_objects(
self, browse_params: BrowseParamsObject
) -> BrowseResponse:
return await self.algolia_client.browse_objects(
index_name=self.name, aggregator=None, browse_params=browse_params
)

async def save_objects_async(
async def save_objects(
self, objects: list[dict[str, Any]]
) -> list[BatchResponse]:
return self.algolia_client.save_objects(self.name, objects)

async def delete_objects_async(self, objectids: list[str]) -> list[BatchResponse]:
async def delete_objects(self, objectids: list[str]) -> list[BatchResponse]:
return self.algolia_client.delete_objects(self.name, objectids)


Expand Down Expand Up @@ -128,17 +128,17 @@ async def __aexit__(
) -> None:
self._logger.debug("Closing MockAlgoliaIndex")

async def save_objects_async(
async def save_objects(
self,
objects: list[dict] | Iterator[dict],
request_options: dict[str, Any] | None = None,
) -> "MockMultiResponse":
"""Mock implementation of save_objects_async."""
"""Mock implementation of save_objects."""
for obj in objects:
self._saved_objects.append(deepcopy(obj))
return MockMultiResponse()

async def browse_objects_async(
async def browse_objects(
self, search_settings: dict[str, Any]
) -> AsyncIterator[dict[str, Any]]:
self._logger.debug("Got search settings %s", search_settings)
Expand All @@ -148,7 +148,7 @@ async def browse_objects_async(
for _ in range(5):
yield {}

async def delete_objects_async(
async def delete_objects(
self, objectids: list[str]
) -> list[DeletedAtResponse]:
return [DeletedAtResponse(task_id=0, deleted_at="") for _ in objectids]
Expand Down
4 changes: 2 additions & 2 deletions astropylibrarian/workflows/deleterooturl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def delete_root_url(

logger.debug("Found %d objects for deletion", len(object_ids))

responses = await algolia_index.delete_objects_async(object_ids)
responses = await algolia_index.delete_objects(object_ids)
logger.debug("Algolia response:\n%s", responses)

logger.info("Deleted %d objects", len(object_ids))
Expand All @@ -47,5 +47,5 @@ async def search_for_records(
obj = BrowseParamsObject(
filters=filters, attributes_to_retrieve=["root_url"], attributes_to_highlight=[]
)
async for result in algolia_index.browse_objects_async(obj):
async for result in algolia_index.browse_objects(obj):
yield result
4 changes: 2 additions & 2 deletions astropylibrarian/workflows/expirerecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def expire_old_records(
attributes_to_highlight=[],
)
old_object_ids: List[str] = []
async for r in algolia_index.browse_objects_async(obj):
async for r in algolia_index.browse_objects(obj):
# Double check that we're deleting the right things.
if r["root_url"] != root_url:
logger.warning("root_url does not match: %s", r["baseUrl"])
Expand All @@ -52,7 +52,7 @@ async def expire_old_records(
root_url,
)

await algolia_index.delete_objects_async(old_object_ids)
await algolia_index.delete_objects(old_object_ids)

logger.info("Finished deleting expired objects for %s", root_url)

Expand Down
2 changes: 1 addition & 1 deletion astropylibrarian/workflows/indexjupyterbookpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def index_jupyterbook_page(
logger.debug(
"Indexing %d records for Jupyter Book page at %s", len(records), url
)
response = await algolia_index.save_objects_async(records)
response = await algolia_index.save_objects(records)
logger.debug("Algolia save_objects: %s", response.raw_responses)

object_ids = [r["objectID"] for r in records]
Expand Down
2 changes: 1 addition & 1 deletion astropylibrarian/workflows/indextutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async def index_tutorial(

saved_object_ids: List[str] = []
try:
response = await algolia_index.save_objects_async(records)
response = await algolia_index.save_objects(records)
except RequestException as e:
logger.error(
"Error saving objects for tutorial %s:\n%s",
Expand Down

0 comments on commit d3bfc80

Please sign in to comment.