fix sql performance for cleaning up old sessions

for better performance avoid calculating the time for every record, instead calculate the compared time once.