mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-15 00:03:38 -07:00
Clean up last commit
This commit is contained in:
parent
ea4cb43479
commit
f1ae0266f1
|
|
@ -15,11 +15,12 @@ namespace DiscordChatExporter.Core.Exporting;
|
||||||
|
|
||||||
internal partial class ExportAssetDownloader
|
internal partial class ExportAssetDownloader
|
||||||
{
|
{
|
||||||
private static readonly AsyncKeyedLocker<string> _locker = new(o =>
|
private static readonly AsyncKeyedLocker<string> Locker = new(o =>
|
||||||
{
|
{
|
||||||
o.PoolSize = 20;
|
o.PoolSize = 20;
|
||||||
o.PoolInitialFill = 1;
|
o.PoolInitialFill = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
private readonly string _workingDirPath;
|
private readonly string _workingDirPath;
|
||||||
private readonly bool _reuse;
|
private readonly bool _reuse;
|
||||||
|
|
||||||
|
|
@ -37,14 +38,15 @@ internal partial class ExportAssetDownloader
|
||||||
var fileName = GetFileNameFromUrl(url);
|
var fileName = GetFileNameFromUrl(url);
|
||||||
var filePath = Path.Combine(_workingDirPath, fileName);
|
var filePath = Path.Combine(_workingDirPath, fileName);
|
||||||
|
|
||||||
using (await _locker.LockAsync(filePath, cancellationToken).ConfigureAwait(false))
|
using (await Locker.LockAsync(filePath, cancellationToken))
|
||||||
{
|
{
|
||||||
if (_pathCache.TryGetValue(url, out var cachedFilePath))
|
if (_pathCache.TryGetValue(url, out var cachedFilePath))
|
||||||
return cachedFilePath;
|
return cachedFilePath;
|
||||||
|
|
||||||
// Reuse existing files if we're allowed to
|
// Reuse existing files if we're allowed to
|
||||||
if (!_reuse || !File.Exists(filePath))
|
if (_reuse && File.Exists(filePath))
|
||||||
{
|
return _pathCache[url] = filePath;
|
||||||
|
|
||||||
Directory.CreateDirectory(_workingDirPath);
|
Directory.CreateDirectory(_workingDirPath);
|
||||||
|
|
||||||
await Http.ResiliencePolicy.ExecuteAsync(async () =>
|
await Http.ResiliencePolicy.ExecuteAsync(async () =>
|
||||||
|
|
@ -78,7 +80,6 @@ internal partial class ExportAssetDownloader
|
||||||
// ignore exceptions thrown here.
|
// ignore exceptions thrown here.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return _pathCache[url] = filePath;
|
return _pathCache[url] = filePath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue