cleanup and save the digest in the database in history mode