Skip to content

Commit

Permalink
Add batch APIs to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
emgarten committed Jan 16, 2019
1 parent 544c788 commit d8069a0
Show file tree
Hide file tree
Showing 25 changed files with 992 additions and 576 deletions.
30 changes: 24 additions & 6 deletions src/SleetLib/Commands/DeleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public static async Task<bool> RunAsync(LocalSettings settings, ISleetFileSystem
};

var packageIndex = new PackageIndex(context);
var existingPackageSets = await packageIndex.GetPackageSetsAsync();

var packages = new List<PackageIdentity>();
var packages = new HashSet<PackageIdentity>();

if (!string.IsNullOrEmpty(version))
{
Expand All @@ -52,18 +53,22 @@ public static async Task<bool> RunAsync(LocalSettings settings, ISleetFileSystem
else
{
// Delete all versions of the package
packages.AddRange(await packageIndex.GetPackagesByIdAsync(packageId));
packages.UnionWith(await existingPackageSets.Packages.GetPackagesByIdAsync(packageId));
packages.UnionWith(await existingPackageSets.Symbols.GetPackagesByIdAsync(packageId));
}

if (string.IsNullOrEmpty(reason))
{
reason = string.Empty;
}

var toRemove = new HashSet<PackageIdentity>();
var toRemoveSymbols = new HashSet<PackageIdentity>();

foreach (var package in packages)
{
var exists = await packageIndex.Exists(package);
var symbolsExists = await packageIndex.SymbolsExists(package);
var exists = existingPackageSets.Packages.Exists(package);
var symbolsExists = existingPackageSets.Symbols.Exists(package);

if (!exists && !symbolsExists)
{
Expand All @@ -80,6 +85,16 @@ public static async Task<bool> RunAsync(LocalSettings settings, ISleetFileSystem
}
}

if (exists)
{
toRemove.Add(package);
}

if (symbolsExists)
{
toRemoveSymbols.Add(package);
}

var message = $"Removing {package.ToString()}";

if (exists && symbolsExists)
Expand All @@ -92,10 +107,13 @@ public static async Task<bool> RunAsync(LocalSettings settings, ISleetFileSystem
}

await log.LogAsync(LogLevel.Information, message);

await SleetUtility.RemovePackage(context, package);
}

// Update feed
await log.LogAsync(LogLevel.Information, "Removing packages from feed locally");
await SleetUtility.RemoveNonSymbolsPackages(context, toRemove);
await SleetUtility.RemoveSymbolsPackages(context, toRemoveSymbols);

// Save all
log.LogMinimal($"Committing changes to {source.BaseURI.AbsoluteUri}");

Expand Down
Loading

0 comments on commit d8069a0

Please sign in to comment.