v0.8.1 sql fixes

Hi Andy,

please pull my SQL performance optimisations into your branch. To make this changes work you need to create an index on table tweets:

CREATE INDEX `tweets_x1` ON `tweets` (time DESC);

with kind regards
thomas