Cache patron's loans to reduce IA requests - #7929
Conversation
for more information, see https://pre-commit.ci
3880023 to
c2f2f1d
Compare
|
I think this is close, but I think we want both the ability to fetch loans and also to fetch cached loans independently. The borrow flow needs to have an authoritative way to fetch loans with no chance of them being cached. Other pages (like where LoanStatus macro fetches loans) should use the cache. |
@mekarpeles I have implement a Also, for all the parent functions of Although I am unable to test loans on local, I have tested the flow of this cache implementation with a basic python script and it is behaving as expected. See picture below: |
|
Currently, the places where we're making expensive calls for a patron's loans and waitlists are:
I believe the only time we want to use cache (for now) is within [1]. I would be nice if we had a new This would get cached for 5 minutes and could be called by any non-critical path, such as [1] LoanStatus. Within the critical paths (borrow endpoints) we should use the expensive, non-cached endpoints). We may be able to leverage the |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
@jimchamp
One issue with my current implementation is that it only caches the user loans, but there is no caching implemented for user's waiting loans yet. Should I do so for waiting loans as well? Is it an expensive call? |
jimchamp
left a comment
There was a problem hiding this comment.
There are quite a few changes to the critical path that I think should be reverted. Holds (AKA waitlist items) are also expensive to fetch and should also be cached.
Now that you're using Open Library's cache, you'll have to invalidate the cache using memcache_delete. The exact invocation that I suggested may not work, so you may need to experiment a bit.
Following Mek's suggestion to create a public get_patron_loans function that returns both loans and holds would be helpful when we expand this functionality to the My Book page.
for more information, see https://pre-commit.ci
|
Since we're only focusing on the LoanStatus buttons for this PR, let's punt on the new |
for more information, see https://pre-commit.ci
| loandata = web.ctx.site.store.values(type='/type/loan', name='user', value=user_key) | ||
| loans = [Loan(d) for d in loandata] + (_get_ia_loans_of_user(account.itemname)) |
There was a problem hiding this comment.
Q: why are we calling both IA loans (which presumably uses s3) and OL web.ctx loans store?
|
finally lgtm!! |

Closes #7591
Implement cache logic that caches patron's loan with 5 minutes time-to-live. If this 5 minute window has passed or if patron has borrowed another book (via
/borrow/ia/$(ocaid)), then the cache will be invalidated => loans will be fetched again via api.Stakeholders
@mekarpeles