Ejemplo n.º 1
0
        public async Task ImportAsync()
        {
            var packageDownloads = await _downloadsSource.GetPackageDownloadsAsync();

            var packages = await _dbContext.GetPackagesCountAsync();// _context.Packages.CountAsync();

            var batches = (packages / BatchSize) + 1;

            for (var batch = 0; batch < batches; batch++)
            {
                _logger.LogInformation("Importing batch {Batch}...", batch);

                var packagesToSave = new List <Package>();
                foreach (var package in await GetBatch(batch))
                {
                    var packageId      = package.Id.ToLowerInvariant();
                    var packageVersion = package.VersionString.ToLowerInvariant();

                    if (!packageDownloads.ContainsKey(packageId) ||
                        !packageDownloads[packageId].ContainsKey(packageVersion))
                    {
                        continue;
                    }

                    package.Downloads = packageDownloads[packageId][packageVersion];
                    packagesToSave.Add(package);
                }

                await _dbContext.AddPackages(packagesToSave);

                _logger.LogInformation("Imported batch {Batch}", batch);
            }
        }