Skip to content

Commit bd785d7

Browse files
make BookPageListsPartial async (#12272)
Co-authored-by: RayBB <RayBB@users.noreply.github.com>
1 parent 2f340b6 commit bd785d7

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

openlibrary/fastapi/partials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def book_page_lists_partial(
8080
8181
At least one of workId or editionId must be provided.
8282
"""
83-
return BookPageListsPartial(workId=workId, editionId=editionId).generate()
83+
return await BookPageListsPartial(workId=workId, editionId=editionId).generate_async()
8484

8585

8686
@router.get("/partials/FulltextSearchSuggestion.json", include_in_schema=SHOW_PARTIALS_IN_SCHEMA)

openlibrary/plugins/openlibrary/lists.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,15 +1055,14 @@ def get_active_lists_in_random(limit=20, preload=True):
10551055
return [web.ctx.site.new(xlist["key"], xlist) for xlist in lists]
10561056

10571057

1058-
@public
1059-
def get_lists(keys: list[str]):
1058+
async def get_lists_async(keys: list[str]):
10601059
# Fetches and caches the lists through Solr, rather than through the DB.
10611060
from openlibrary.core.lists.model import List
1062-
from openlibrary.plugins.worksearch.code import run_solr_query
1061+
from openlibrary.plugins.worksearch.code import run_solr_query_async
10631062
from openlibrary.plugins.worksearch.schemes.lists import ListSearchScheme
10641063

10651064
or_query = " OR ".join(f'"{k}"' for k in keys)
1066-
response = run_solr_query(
1065+
response = await run_solr_query_async(
10671066
param={"q": f"seed:({or_query})"},
10681067
scheme=ListSearchScheme(),
10691068
fields=["key"],

openlibrary/plugins/openlibrary/partials.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from openlibrary.core.fulltext import fulltext_search_async
1111
from openlibrary.core.lending import compose_ia_url, get_available
1212
from openlibrary.i18n import gettext as _
13-
from openlibrary.plugins.openlibrary.lists import get_lists, get_user_lists
13+
from openlibrary.plugins.openlibrary.lists import get_lists_async, get_user_lists
1414
from openlibrary.plugins.upstream.yearly_reading_goals import get_reading_goals
1515
from openlibrary.plugins.worksearch.code import do_search, work_search
1616
from openlibrary.plugins.worksearch.subjects import (
@@ -293,11 +293,14 @@ def __init__(self, workId: str, editionId: str):
293293
self.editionId = editionId
294294

295295
def generate(self) -> dict:
296+
raise NotImplementedError("Use generate_async instead")
297+
298+
async def generate_async(self) -> dict:
296299
results: dict = {"partials": []}
297300
keys = [k for k in (self.workId, self.editionId) if k]
298301

299302
# Do checks and render
300-
lists = get_lists(keys)
303+
lists = await get_lists_async(keys)
301304
results["hasLists"] = bool(lists)
302305

303306
if not lists:

0 commit comments

Comments
 (0)