mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-13 10:48:26 -04:00
Added and applied styles for private readonly fields, private fields to Extensions and Common folders.
- Some renamings and code cleanups - Chained method calls, binary expressions and binary patterns will now break into newlines - Type param constraints and base constructor calls will be on the new line
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
public class DownloadTracker : INService
|
||||
{
|
||||
private ConcurrentDictionary<ulong, DateTime> LastDownloads { get; } = new();
|
||||
private readonly SemaphoreSlim downloadUsersSemaphore = new(1, 1);
|
||||
private readonly SemaphoreSlim _downloadUsersSemaphore = new(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Ensures all users on the specified guild were downloaded within the last hour.
|
||||
@@ -12,16 +12,16 @@ public class DownloadTracker : INService
|
||||
/// <returns>Task representing download state</returns>
|
||||
public async Task EnsureUsersDownloadedAsync(IGuild guild)
|
||||
{
|
||||
await downloadUsersSemaphore.WaitAsync();
|
||||
await _downloadUsersSemaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
// download once per hour at most
|
||||
var added = LastDownloads.AddOrUpdate(
|
||||
guild.Id,
|
||||
var added = LastDownloads.AddOrUpdate(guild.Id,
|
||||
now,
|
||||
(key, old) => now - old > TimeSpan.FromHours(1) ? now : old);
|
||||
(_, old) => now - old > TimeSpan.FromHours(1) ? now : old
|
||||
);
|
||||
|
||||
// means that this entry was just added - download the users
|
||||
if (added == now)
|
||||
@@ -29,7 +29,7 @@ public class DownloadTracker : INService
|
||||
}
|
||||
finally
|
||||
{
|
||||
downloadUsersSemaphore.Release();
|
||||
_downloadUsersSemaphore.Release();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user