Exemple #1
0
        private async Task UpdateLeavesAsync(
            HiveType hive,
            IReadOnlyList <HiveType> replicaHives,
            string id,
            Dictionary <NuGetVersion, PackageDetailsCatalogLeaf> versionToCatalogLeaf,
            CatalogCommit registrationCommit,
            HiveMergeResult mergeResult)
        {
            if (!mergeResult.ModifiedLeaves.Any())
            {
                _logger.LogInformation("No leaves need to be updated.");
                return;
            }

            _logger.LogInformation(
                "Updating {Count} registration leaves.",
                mergeResult.ModifiedLeaves.Count,
                id,
                hive);

            var taskFactories = new ConcurrentBag <Func <Task> >();

            foreach (var leafInfo in mergeResult.ModifiedLeaves)
            {
                _entityBuilder.UpdateLeafItem(leafInfo.LeafItem, hive, id, versionToCatalogLeaf[leafInfo.Version]);
                _entityBuilder.UpdateCommit(leafInfo.LeafItem, registrationCommit);
                var leaf = _entityBuilder.NewLeaf(leafInfo.LeafItem);
                taskFactories.Add(async() =>
                {
                    _logger.LogInformation("Updating leaf {PackageId} {Version}.", id, leafInfo.Version.ToNormalizedString());
                    await _storage.WriteLeafAsync(hive, replicaHives, id, leafInfo.Version, leaf);
                });
            }

            await ParallelAsync.Repeat(
                async() =>
            {
                await Task.Yield();
                while (taskFactories.TryTake(out var taskFactory))
                {
                    await taskFactory();
                }
            },
                _options.Value.MaxConcurrentOperationsPerHive);
        }