Don't update the session unless it changes

And deadband session token updates to 1 per 30 seconds
Don't fetch ticket thread unless necessary
Don't generate staff statistics for AJAX requests
Periodically optimize core tables

This is instead of optimizing the lock table for every cron run, which
wastes a lot of db server io
Merge pull request #415 from greezybacon/db-perf-tweaks

Several database performance tweaks

Reviewed-By: Peter Rotich <peter@osticket.com>