Fix doctrine context errors when iterating whith batch queries

batch messages are duplicated when optimize method cleans the doctrine context