Skip to content

Commit 6ec93d5

Browse files
make FulltextSearchSuggestion partial async (#12265)
Co-authored-by: Raymond Berger <RayBB@users.noreply.github.com>
1 parent abb65bf commit 6ec93d5

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

openlibrary/fastapi/partials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def fulltext_search_suggestion_partial(
9494
The data parameter is the raw search query string.
9595
"""
9696
partial = FullTextSuggestionsPartial(query=data)
97-
result = partial.generate()
97+
result = await partial.generate_async()
9898

9999
if not partial.has_error:
100100
response.headers["Cache-Control"] = "public, max-age=300"

openlibrary/plugins/openlibrary/partials.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from infogami.utils.view import render_template
99
from openlibrary.accounts import get_current_user
10-
from openlibrary.core.fulltext import fulltext_search
10+
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 _
1313
from openlibrary.plugins.openlibrary.lists import get_lists, get_user_lists
@@ -268,8 +268,11 @@ def __init__(self, query: str):
268268
self.has_error: bool = False
269269

270270
def generate(self) -> dict:
271+
raise NotImplementedError("Use generate_async instead")
272+
273+
async def generate_async(self) -> dict:
271274
query = self.query
272-
data = fulltext_search(query)
275+
data = await fulltext_search_async(query)
273276
# Add caching headers only if there were no errors in the search results
274277
self.has_error = "error" in data
275278
hits = data.get('hits', [])

0 commit comments

Comments
 (0)