private async Task Bootstrap() { _logger.LogInformation($"[{Name}] Checking Bootstrap Status..."); var start = DateTime.UtcNow; var totalCount = 0; var missingCellIds = new List <ulong>(); // Loop all geofences and get s2cells within each foreach (var polygon in MultiPolygon) { // Get max amount of s2 level 15 cells within this geofence var s2Cells = polygon.GetS2CellIds(15, int.MaxValue); var s2CellIds = s2Cells.Select(x => x.Id).ToList(); totalCount += s2CellIds.Count; // Get all known cells from the database var cells = await _cellRepository.GetByIdsAsync(s2CellIds, false).ConfigureAwait(false); // Map to just s2cell ids var existingCellIds = cells.Select(x => x.Id).ToList(); // Loop all s2cells within geofence and check if any are missing foreach (var s2cellId in s2CellIds) { // Check if we don't have the s2cell in the database if (!existingCellIds.Contains(s2cellId)) { // Add to bootstrap s2cell list missingCellIds.Add(s2cellId); } } } missingCellIds = missingCellIds.Distinct().ToList(); missingCellIds.Sort(); _logger.LogInformation($"[{Name}] Bootstrap Status: {totalCount - missingCellIds.Count}/{totalCount} after {DateTime.UtcNow.Subtract(start).TotalSeconds:N0} seconds"); lock (_bootstrapLock) { _bootstrapCellIds = missingCellIds; _bootstrapTotalCount = totalCount; } }