Skip to content

Instantly share code, notes, and snippets.

@matthumphreys
Created December 18, 2014 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthumphreys/aaebc6c18d133145c9db to your computer and use it in GitHub Desktop.
Save matthumphreys/aaebc6c18d133145c9db to your computer and use it in GitHub Desktop.
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
hours_old < 72
ORDER BY total DESC LIMIT 50;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment