Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache language autocomplete inputs/endpoints #9112

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions openlibrary/plugins/openlibrary/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export default function($) {
const term = options.termPreprocessor(q.term);
const params = {
q: term,
limit: options.max,
timestamp: new Date()
limit: options.max
};
if (location.search.indexOf('lang=') !== -1) {
params.lang = new URLSearchParams(location.search).get('lang');
Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/worksearch/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class languages_autocomplete(delegate.page):
def GET(self):
i = web.input(q="", limit=5)
i.limit = safeint(i.limit, 5)
web.header("Cache-Control", "max-age=%d" % (24 * 3600))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is little value in caching this ; it's very unlikely a user will type the same thing twice! In general, it's not super likely a user will type the same thing many times. I imagine a veeeeeery tiny percentage of user searches will be cache hits; most will be misses. I think we might want to roll this back, and cache it only in the case we care about.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdrini this comes from a librarian commenting of the lag that happens when searching languages. I don't know what exactly they're editing that they see it often enough to comment.

How about after the deploy goes how to we check how many requests this endpoint is getting on average? Also we can follow up with that librarian to see what their use case it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw this caching works across pages so if someone edits one book to add a language the next time they do that on any book it'll use the cache.

return to_json(
list(itertools.islice(utils.autocomplete_languages(i.q), i.limit))
)
Expand Down
Loading