Skip to content

Instantly share code, notes, and snippets.

View matthumphreys's full-sized avatar

Matt Humphreys matthumphreys

  • Metro UK
  • London
View GitHub Profile
@matthumphreys
matthumphreys / news-feed.sql
Created December 18, 2014 15:21
I optimised our news feed stored procedure to be 10x faster (with 10x less code)
SELECT id, url, json,
TIMESTAMPDIFF(HOUR, create_date, now()) AS hours_old,
( ( views + (shares * 25)
+ IF(FIND_IN_SET('arsenal-fc,liverpool-fc', post_tags), 10000, 0) )
/ 1
) total
FROM articles WHERE
category = 'sport' AND
FIND_IN_SET(id, '4964027,4963575') = false
HAVING