Openlibrary: Homepage Sponsor Carousel shouldn't hit AMZ

Created on 13 Dec 2019  路  6Comments  路  Source: internetarchive/openlibrary

Cacheing homepage takes a long time because of the Sponsor Carousel. This carousel only contains staff picked books which are already deemed sponsorable, so the only reason they wouldn't be sponsorable is if they are out of stock -- so we should limit our check to that (using BWB API only).

See solution proposal below under Related Files

Relevant url?


home page

Steps to Reproduce

  1. Go to openlibrary.org (when it refreshes it's cache)

Proposal & Constraints

Only check BWB API (core.vendors.py) instead of using the full sponsorship check

Related files

The call path is:
https://github.com/internetarchive/openlibrary/blob/ff191ee9e142dc43f1b239b776223373bbd101c4/openlibrary/templates/home/index.html#L9 to
https://github.com/internetarchive/openlibrary/blob/9602cd22aa5716820bb3fc847e035e8e1de808aa/openlibrary/plugins/openlibrary/home.py#L113-L123
which calls get_sponsorable_editions from openlibrary.core.sponsorships:
https://github.com/internetarchive/openlibrary/blob/ff191ee9e142dc43f1b239b776223373bbd101c4/openlibrary/core/sponsorships.py#L40-L51

The qualifies_for_sponsorship check:
https://github.com/internetarchive/openlibrary/blob/ff191ee9e142dc43f1b239b776223373bbd101c4/openlibrary/core/sponsorships.py#L48 is what needs to switched out in get_sponsorable_editions to something that only checks BWB -- i.e. get_betterworldbooks_metadata(edition.isbn).get('price_amt')

i.e. replace https://github.com/internetarchive/openlibrary/blob/ff191ee9e142dc43f1b239b776223373bbd101c4/openlibrary/core/sponsorships.py#L48-L49 with:

if get_betterworldbooks_metadata(edition.isbn).get('price_amt')

@mekarpeles 2 Work In Progress Book Sponsorship Performance Bug

All 6 comments

Hi,
I would like to try this issue. This is what I understand from the above:
candidates = web.ctx.site.get('/sponsorship/books').get('editions') will return books that are sponsorable unless it is out of stock. qualifies_for_sponsorship(ed) will do unnecessary checks(in this case) besides checking the stock and for making it faster we use get_betterworldbooks_metadata(edition.isbn).get('price_amt') instead to check if it is on stock.
Does get betterworldbooks_metadata(edition.isbn).get('price_amt') return False if the book is out of stock or do we need to wrap it up in a function and deal with those cases?

Hi @hari-govind try using this BWB api call http://products.betterworldbooks.com/service.aspx?ItemId=isbn where you can put in any isbn and check whether it returns false/ the price based on the availability. You would then just need to change these lines above as mentioned by @mekarpeles for them to work. Looking forward to a pr from you :)

I've been trying for a while but I cannot view sponsored books section in the development version. I've tried importing the test data and checking the admin dashboard for relevant options but was unable to figure out how to enable the "Books to Sponsor" section and add books to that section.

Hi @hari-govind -- sending you a slack invite (received your email) and happy to help you through this issue. We may be something we have to open a PR for without testing, and then test on dev.openlibrary.org. The other option (which I think you should pursue) is... in openlibrary/core/sponsorship.py in get_sponsorable_editions, replace the line candidates = ... within the try block with a list of books that you know are on your local developer instance. This way you can test locally.

Sorry I was very busy for two days but I see it is already fixed in the mean time. I'll tackle some other simple fixes like this. Thanks for letting me in on Slack @mekarpeles :)

@hari-govind please do! This specific issue is Priority 1 (i.e. this / next week) which is why I jumped in to help :)

Was this page helpful?
0 / 5 - 0 ratings