trending based on twitter mentions and facebook likes

428 views Asked by At

Our website allow people to upload images and then share them on twitter and/or like them on facebook. There's a trending page with the top X images based on the total number of twitter mentions and facebook likes of a specific page.

The only way at the moment I can see we could achieve that is by making 2 API calls (at least) on every single image to get the count for each social website and then calculate the total to finally order the images by the most "trending" first. I don't think that's the way it should be as it could possibily take ages to do this if we have, let's say, 3000 images to order.

I have no idea on how to achieve what we want (and if it is even possible), that's why the only solutions I can think of for now is either to have our own "like" system or to get the counts hourly and creating a kind of cache (but that would still mean a LOT of API calls to to every hour).

2

There are 2 answers

1
Jonathan On

Maybe you can just rank images based on the number of views on your server. If you'd like you can take the 10% best viewed images and rank those based on mentions/likes (as well). This requires 90% less API calls but gives a satisfying result (I think).

1
Nick On

A few suggestions:

  1. Limit it to a certain timeframe (e.g. images uploaded in the past week)
  2. Cache the data for a length of time, only do an API call per image every hour or so (maybe even longer)
  3. Do API calls for this even when people aren't on this page, any other time the image is loaded elsewhere on the site, do an API call if it hasn't been done in the past hour. This would stagger the amount of requests on one page load.
  4. Limit the amount of requests in one page load. This means that someone might load a page, it would only send 100 requests off (for the 100 images that haven't been requested in the longest time), and the rest of the images would use the value they were at previously (i.e. a cached value). This one completely depends on how active your site is though, you might also need to do a daily/weekly lookup of all of them to make sure the cache doesn't go too far out of date.