public async Task <ActionResult <List <DataBlockQuerySizeReport> > > QuerySizeReport() { var publishedReleaseIds = _contentDbContext.Releases .Include(r => r.Publication) .ToList() .Where(r => r.Publication.IsLatestVersionOfRelease(r.Id)) .Select(r => r.Id) .ToList(); var publishedDataBlocks = await _contentDbContext.ReleaseContentBlocks .Include(rcb => rcb.ContentBlock) .Where(rcb => publishedReleaseIds.Contains(rcb.ReleaseId)) .Select(rcb => rcb.ContentBlock) .OfType <DataBlock>() .ToListAsync(); return(await publishedDataBlocks .ToAsyncEnumerable() .SelectAwait(async dataBlock => { var query = dataBlock.Query; var countsOfFilterItemsByFilter = await _filterItemRepository .CountFilterItemsByFilter(dataBlock.Query.Filters); var countOfIndicators = query.Indicators.Count(); var countOfLocations = query.LocationIds.Count; var countOfTimePeriods = TimePeriodUtil.Range(query.TimePeriod).Count(); var maxTableCellCount = TableBuilderUtils.MaximumTableCellCount( countOfIndicators: countOfIndicators, countOfLocations: countOfLocations, countOfTimePeriods: countOfTimePeriods, countsOfFilterItemsByFilter: countsOfFilterItemsByFilter .Select(pair => { var(_, count) = pair; return count; })); return new DataBlockQuerySizeReport { DataBlockId = dataBlock.Id, DataBlockName = dataBlock.Name, Filters = countsOfFilterItemsByFilter, Indicators = countOfIndicators, Locations = countOfLocations, TimePeriods = countOfTimePeriods, MaxTableCells = maxTableCellCount }; }) .OrderByDescending(result => result.MaxTableCells) .ToListAsync()); }
private async Task <int> GetMaximumTableCellCount(ObservationQueryContext queryContext) { var filterItemIds = queryContext.Filters; var countsOfFilterItemsByFilter = filterItemIds == null ? new List <int>() : (await _filterItemRepository.CountFilterItemsByFilter(filterItemIds)) .Select(pair => { var(_, count) = pair; return(count); }) .ToList(); // TODO Accessing time periods for the Subject by altering the Importer to store them would improve accuracy // here rather than assuming the Subject has all time periods between the start and end range. return(TableBuilderUtils.MaximumTableCellCount( countOfIndicators: queryContext.Indicators.Count(), countOfLocations: queryContext.LocationIds.Count, countOfTimePeriods: TimePeriodUtil.Range(queryContext.TimePeriod).Count, countsOfFilterItemsByFilter: countsOfFilterItemsByFilter )); }