If things get slow and busy or things are broken, I'll have to work on it some more (it's been months since I last touched this code... may have some bitrot).
The major difference now is that this is all hitting the slave database, not the main one. Enjoy.
Update: I posted this a few minutes early so I deleted it. Opiummmm --- you can post your comment again. :-)
Update again: Yeah ... it still needs a bunch of work. At least we have the hardware to run it on now, once it's fixed up.
Update3: I'm rewriting it .... I think I found a much better way to do it which makes it faster.
Update4: It's signifigantly faster now but there are tons of more things I'm going to do to keep improving it... Bear with me.