Skip to content

Commit

Permalink
perf: faster library refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed May 12, 2024
1 parent 269c9ea commit 1353ed2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/PipManager/Services/Environment/EnvironmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Documents;
using Python.Runtime;
using Wpf.Ui.Controls;
using Path = System.IO.Path;
Expand Down Expand Up @@ -94,7 +96,7 @@ public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem)
if (packageName == "pip") return;
// Metadata
var metadataDict = new Dictionary<string, List<string>>();
var metadataDict = new Dictionary<string, List<StringBuilder>>();
var lastValidKey = "";
var lastValidIndex = 0;
var classifiers = new Dictionary<string, List<string>>();
Expand All @@ -121,15 +123,18 @@ await foreach (var line in File.ReadLinesAsync(Path.Combine(distInfoDirectoryFul
lastValidIndex++;
}
metadataDict[key].Add(value);
metadataDict[key].Add(new StringBuilder(value));
}
else
{
metadataDict[lastValidKey][lastValidIndex] += "\n" + value;
metadataDict[lastValidKey][lastValidIndex].Append('\n').Append(value);
}
}
foreach (var item in metadataDict.GetValueOrDefault("classifier", []))
var metadata = metadataDict.ToDictionary(
pair => pair.Key,
pair => pair.Value.Select(sb => sb.ToString()).ToList()
);
foreach (var item in metadata.GetValueOrDefault("classifier", []))
{
var keyValues = item.Split(" :: ");
Expand Down Expand Up @@ -165,7 +170,7 @@ await foreach (var line in File.ReadLinesAsync(Path.Combine(distInfoDirectoryFul
}
// Extra
var projectUrl = metadataDict.GetValueOrDefault("project-url", []);
var projectUrl = metadata.GetValueOrDefault("project-url", []);
var projectUrlDictionary = new List<LibraryDetailProjectUrlModel>();
if (projectUrl.Count != 0)
Expand Down Expand Up @@ -211,13 +216,13 @@ await foreach (var line in File.ReadLinesAsync(Path.Combine(distInfoDirectoryFul
DetailedVersion = PackageValidator.CheckVersion(packageVersion),
Path = actualPath,
DistInfoPath = distInfoDirectoryFullName,
Summary = metadataDict.GetValueOrDefault("summary", [""])[0],
Author = metadataDict.GetValueOrDefault("author", []),
AuthorEmail = metadataDict.GetValueOrDefault("author-email", [""])[0],
Summary = metadata.GetValueOrDefault("summary", [""])[0],
Author = metadata.GetValueOrDefault("author", []),
AuthorEmail = metadata.GetValueOrDefault("author-email", [""])[0],
ProjectUrl = projectUrlDictionary,
Classifier = classifiers,
RequiresDist = metadataDict.GetValueOrDefault("requires-dist", []),
Metadata = metadataDict,
RequiresDist = metadata.GetValueOrDefault("requires-dist", []),
Metadata = metadata,
Record = record
});
});
Expand Down

0 comments on commit 1353ed2

Please sign in to comment.