Skip to content

Commit bc84910

Browse files
committed
Use static HttpClient instance for heavy load issue
1 parent cc0fb66 commit bc84910

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
1717
{
1818
internal class PluginsManager
1919
{
20-
const string zip = "zip";
20+
private static readonly HttpClient HttpClient = new();
21+
22+
private const string zip = "zip";
2123

2224
private PluginInitContext Context { get; set; }
2325

@@ -151,8 +153,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
151153
if (File.Exists(filePath))
152154
File.Delete(filePath);
153155

154-
using var httpClient = new HttpClient();
155-
using var response = await httpClient.GetAsync(plugin.UrlDownload, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
156+
using var response = await HttpClient.GetAsync(plugin.UrlDownload, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
156157

157158
response.EnsureSuccessStatusCode();
158159

@@ -165,7 +166,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
165166
{
166167
if (prgBox != null)
167168
{
168-
httpClient.CancelPendingRequests();
169+
HttpClient.CancelPendingRequests();
169170
downloadCancelled = true;
170171
prgBox = null;
171172
}

0 commit comments

Comments
 (0)