Optimized history performance by making one sql statement to fetch revisions