Precalculate and persist grouping-IDs