optimise queries on queue_log

when casting text into timestamp, postgres can't use
the index to speed up queries, which has a huge impact
on big datasets
fix unit tests in stat dao v2
fix syntax error in SQL query
Merge branch 'stat_optimisations'