You could probably optimize the performance if you put the delete in a cron jobs rather than an online query which executes each time a page is loaded.