Skip to content

Commit

Permalink
perf: higher performance in libraryList
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Feb 5, 2024
1 parent bf1cdd4 commit 37752ce
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 72 deletions.
10 changes: 1 addition & 9 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param(
[string] $Architecture = "x64",
[string] $Version = "0.0.0.2"
[string] $Version = "0.0.0.3"
)

$ErrorActionPreference = "Stop";
Expand All @@ -15,14 +15,6 @@ Write-Output "Start building singleWithoutRuntime...";

dotnet publish src/PipManager -c Release -r "win-$Architecture" -o "build/$Version/singleWithoutRuntime" -p:Platform=$Architecture -p:PublishReadyToRun=false -p:EnableCompressionInSingleFile=false -p:PublishSingleFile=true -p:SelfContained=false -p:AssemblyVersion=$Version;

Write-Output "Start building extractedWithRuntime...";

dotnet publish src/PipManager -c Release -r "win-$Architecture" -o "build/$Version/extractedWithRuntime" -p:Platform=$Architecture -p:PublishReadyToRun=true -p:EnableCompressionInSingleFile=false -p:PublishSingleFile=false -p:SelfContained=true -p:AssemblyVersion=$Version;

Write-Output "Start building extractedWithoutRuntime...";

dotnet publish src/PipManager -c Release -r "win-$Architecture" -o "build/$Version/extractedWithoutRuntime" -p:Platform=$Architecture -p:PublishReadyToRun=true -p:EnableCompressionInSingleFile=false -p:PublishSingleFile=false -p:SelfContained=false -p:AssemblyVersion=$Version;

Write-Output "Build Finished";

[Console]::ReadKey()
7 changes: 7 additions & 0 deletions src/PipManager.PackageSearch/PipManager.PackageSearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>embedded</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace PipManager.Models.Pages;

public class LibraryDetailProjectUrlModel
{
public SymbolIcon? Icon { get; set; }
public SymbolRegular? Icon { get; set; }
public string? UrlType { get; set; }
public string? Url { get; set; }
}
114 changes: 55 additions & 59 deletions src/PipManager/Services/Environment/EnvironmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
using PipManager.Models.Pypi;
using PipManager.Services.Configuration;
using PipManager.Services.Environment.Response;
using Serilog;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Windows.Threading;
using Wpf.Ui.Controls;
using Path = System.IO.Path;

Expand All @@ -34,23 +37,23 @@ public ActionResponse CheckEnvironmentAvailable(EnvironmentItem environmentItem)
: new ActionResponse { Success = false, Exception = ExceptionType.Environment_Broken };
}

public List<PackageItem>? GetLibraries()
public async Task<List<PackageItem>?> GetLibraries()
{
if (configurationService.AppConfig.CurrentEnvironment is null)
{
return null;
}

var packageLock = new object();
var packageDirInfo = new DirectoryInfo(Path.Combine(
Path.GetDirectoryName(configurationService.AppConfig.CurrentEnvironment!.PythonPath)!,
@"Lib\site-packages"));
var packages = new List<PackageItem>();
var packages = new ConcurrentBag<PackageItem>();
var ioTaskList = new List<Task>();
foreach (var distInfoDirectory in packageDirInfo.GetDirectories()
.Where(path => path.Name.EndsWith(".dist-info")).ToList())
var distInfoDirectories = packageDirInfo.GetDirectories()
.Where(path => path.Name.EndsWith(".dist-info")).ToList();
foreach (var distInfoDirectory in distInfoDirectories)
{
var task = Task.Run(() =>
var task = Task.Run(async() =>
{
var distInfoDirectoryFullName = distInfoDirectory.FullName;
var distInfoDirectoryName = distInfoDirectory.Name;
Expand All @@ -66,7 +69,7 @@ public ActionResponse CheckEnvironmentAvailable(EnvironmentItem environmentItem)
var lastValidKey = "";
var lastValidPos = 0;
var classifiers = new Dictionary<string, List<string>>();
foreach (var line in File.ReadLines(Path.Combine(distInfoDirectoryFullName, "METADATA")))
await foreach (var line in File.ReadLinesAsync(Path.Combine(distInfoDirectoryFullName, "METADATA")))
{
if (line == "")
{
Expand Down Expand Up @@ -120,7 +123,7 @@ public ActionResponse CheckEnvironmentAvailable(EnvironmentItem environmentItem)
// Record
var record = new List<string>();
var actualPath = "";
foreach (var line in File.ReadLines(Path.Combine(distInfoDirectoryFullName, "RECORD")))
await foreach (var line in File.ReadLinesAsync(Path.Combine(distInfoDirectoryFullName, "RECORD")))
{
var dirIdentifier = line.Split('/')[0];
if (dirIdentifier == distInfoDirectoryName || dirIdentifier[0] == '.') continue;
Expand All @@ -134,67 +137,60 @@ public ActionResponse CheckEnvironmentAvailable(EnvironmentItem environmentItem)
// Extra
var projectUrl = metadataDict.GetValueOrDefault("project-url", []);
var projectUrlDictionary = new List<LibraryDetailProjectUrlModel>();
Application.Current.Dispatcher.Invoke(() =>

if (projectUrl.Count != 0)
{
if (projectUrl.Count != 0)
{
projectUrlDictionary.AddRange(projectUrl.Select(url => new LibraryDetailProjectUrlModel
{
Icon = url.Split(", ")[0].ToLower() switch
{
"homepage" or "home" => new SymbolIcon(SymbolRegular.Home24),
"download" => new SymbolIcon(SymbolRegular.ArrowDownload24),
"changelog" or "changes" or "release notes" => new SymbolIcon(SymbolRegular
.ClipboardTextEdit24),
"bug tracker" or "issue tracker" or "bug reports" or "issues" or "tracker" =>
new SymbolIcon(SymbolRegular.Bug24),
"source code" or "source" or "repository" or "code" => new SymbolIcon(SymbolRegular
.Code24),
"funding" or "donate" or "donations" => new SymbolIcon(SymbolRegular.Money24),
"documentation" => new SymbolIcon(SymbolRegular.Document24),
"commercial" => new SymbolIcon(SymbolRegular.PeopleMoney24),
"support" => new SymbolIcon(SymbolRegular.PersonSupport24),
"chat" or "q & a" => new SymbolIcon(SymbolRegular.ChatHelp24),
_ => new SymbolIcon(SymbolRegular.Link24)
},
UrlType = url.Split(", ")[0],
Url = url.Split(", ")[1]
}));
}
else
projectUrlDictionary.AddRange(projectUrl.Select(url => new LibraryDetailProjectUrlModel
{
projectUrlDictionary.Add(new LibraryDetailProjectUrlModel
Icon = url.Split(", ")[0].ToLower() switch
{
Icon = new SymbolIcon(SymbolRegular.Question24),
UrlType = "Unknown",
Url = ""
});
}
});

lock (packageLock)
"homepage" or "home" => SymbolRegular.Home24,
"download" => SymbolRegular.ArrowDownload24,
"changelog" or "changes" or "release notes" => SymbolRegular
.ClipboardTextEdit24,
"bug tracker" or "issue tracker" or "bug reports" or "issues" or "tracker" =>
SymbolRegular.Bug24,
"source code" or "source" or "repository" or "code" => SymbolRegular
.Code24,
"funding" or "donate" or "donations" => SymbolRegular.Money24,
"documentation" => SymbolRegular.Document24,
"commercial" => SymbolRegular.PeopleMoney24,
"support" => SymbolRegular.PersonSupport24,
"chat" or "q & a" => SymbolRegular.ChatHelp24,
_ => SymbolRegular.Link24
},
UrlType = url.Split(", ")[0],
Url = url.Split(", ")[1]
}));
}
else
{
packages.Add(new PackageItem
projectUrlDictionary.Add(new LibraryDetailProjectUrlModel
{
Name = packageName,
Version = packageVersion,
DetailedVersion = PackageValidator.CheckVersion(packageVersion),
Path = actualPath,
DistInfoPath = distInfoDirectoryFullName,
Summary = metadataDict.GetValueOrDefault("summary", [""])[0],
Author = metadataDict.GetValueOrDefault("author", []),
AuthorEmail = metadataDict.GetValueOrDefault("author-email", [""])[0],
ProjectUrl = projectUrlDictionary,
Classifier = classifiers,
Metadata = metadataDict,
Record = record
Icon = SymbolRegular.Question24,
UrlType = "Unknown",
Url = ""
});
}
packages.Add(new PackageItem
{
Name = packageName,
Version = packageVersion,
DetailedVersion = PackageValidator.CheckVersion(packageVersion),
Path = actualPath,
DistInfoPath = distInfoDirectoryFullName,
Summary = metadataDict.GetValueOrDefault("summary", [""])[0],
Author = metadataDict.GetValueOrDefault("author", []),
AuthorEmail = metadataDict.GetValueOrDefault("author-email", [""])[0],
ProjectUrl = projectUrlDictionary,
Classifier = classifiers,
Metadata = metadataDict,
Record = record
});
});
ioTaskList.Add(task);
}

Task.WaitAll([.. ioTaskList]);
await Task.WhenAll([.. ioTaskList]);
return [.. packages.OrderBy(x => x.Name)];
}

Expand Down
2 changes: 1 addition & 1 deletion src/PipManager/Services/Environment/IEnvironmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IEnvironmentService

public ActionResponse CheckEnvironmentAvailable(EnvironmentItem environmentItem);

public List<PackageItem>? GetLibraries();
public Task<List<PackageItem>?> GetLibraries();

public Task<GetVersionsResponse> GetVersions(string packageName);

Expand Down
4 changes: 2 additions & 2 deletions src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ private async Task RefreshLibrary()
EnvironmentFoundVisible = false;
return;
}
await Task.Run(() =>
await Task.Run(async () =>
{
_library = _environmentService.GetLibraries();
_library = await _environmentService.GetLibraries();
}).ContinueWith(_ =>
{
_maskService.Hide();
Expand Down

0 comments on commit 37752ce

Please sign in to comment.