optimise query that runs every 10 minutes and takes out the user table