-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cache all QueryCarousels by shortening cache key prefix by md5 hashing `args` and `kwargs` for cache keys * Include name of cached macro in cache key * Option to prevent caching select carousels Avoids caching the book page related works carousel, which is fetched after the page loads. Also prevents the homepage "Classic Books" carousel from being cached, as the homepage itself is cached for the same amount of time. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Mek <michael.karpeles@gmail.com>
- Loading branch information
1 parent
ae33dd7
commit d3bb158
Showing
7 changed files
with
67 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
$def with(query, title=None, sort='new', key='', limit=20, search=False, has_fulltext_only=True, url=None, layout='carousel') | ||
|
||
$# Takes following parameters | ||
$# * query (str) -- Any arbitrary Open Library search query, e.g. subject:"Textbooks" | ||
$# * title (str) -- A title to show above the carousel (links to /search?q=query) | ||
$# * sort (str) -- optional sort param defined within work_search.py `work_search` | ||
$# * key (str) -- unique name of the carousel in analytics | ||
$# * limit (int) -- initial number of books to pull | ||
$# * search (bool) -- whether to include search within collection | ||
$# * layout (str) -- layout type, default 'carousel', currently also supports 'grid' | ||
|
||
$# Enable search within this query | ||
$if search: | ||
<form action="/search" class="olform pagesearchbox"> | ||
<input type="hidden" name="q" value="$query"/> | ||
$if has_fulltext_only: | ||
<input type="hidden" name="has_fulltext" value="true"/> | ||
<input type="text" placeholder="$_('Search collection')" name="q2"/> | ||
<input type="submit"/> | ||
</form> | ||
|
||
$code: | ||
# Limit to just fields needed to render carousels | ||
params = { 'q': query, 'fields': 'key,title,subtitle,author_name,cover_i,ia,availability,id_project_gutenberg,id_librivox,id_standard_ebooks,id_openstax' } | ||
# Don't need fields in the search UI url, since they don't do anything there | ||
url = url or "/search?" + urlencode({'q': query}) | ||
if has_fulltext_only: | ||
params['has_fulltext'] = 'true' | ||
|
||
results = work_search(params, sort=sort, limit=limit, facet=False) | ||
books = [storage(b) for b in (results.get('docs', []))] | ||
load_more = {"url": "/search.json?" + urlencode(params), "limit": limit } | ||
|
||
$:render_template("books/custom_carousel", books=books, title=title, url=url, key=key, load_more=load_more, layout=layout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters