Approach 1. Store intermediate results (once in a period in background)
E.g. table ACTIVITY_STATISTICS (may be metrics table can be used) with fields:
Request statistics for dateX:
1. Select from ACTIVITY_STATISTICS where datetime <= dateX
2. Calculate statistics for the residuary period (datetime, dateX]
3. Aggregate the results
1. What if history cleanup has run?
2. What if delete historic process instance was called?
1. Correct the data in statistics table before removal -> can be tricky as new data at the same time can be coming and we can't just move the datetime, we then need to take into account the whole delta: removed + added. This can slow down history cleanup.
2. Clean all previously stored statistics and recalculate it period by period -> in case of constantly running history cleanup won't work.
Sacrifice the accuracy and not correct the data after it was added (the same as Optimize do).
Only allow selecting statistics (and showing hashmap) for some period. + Make the period selectable and default period configurable on the front-end.
To be discussed.