forked from ddrilling/AsbCloudServer
Deleted .DeleteOldRequests() from TelemetryTracker
This commit is contained in:
parent
4d8780dabc
commit
f800e23aab
@ -11,12 +11,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
public class TelemetryTracker : ITelemetryTracker
|
||||
{
|
||||
private Dictionary<string, DateTime> requests;
|
||||
private readonly TimeSpan timeout;
|
||||
|
||||
public TelemetryTracker(CacheDb cacheDb)
|
||||
{
|
||||
timeout = TimeSpan.FromDays(7);
|
||||
|
||||
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||
.Options;
|
||||
@ -39,25 +36,13 @@ namespace AsbCloudInfrastructure.Services
|
||||
}).ToDictionary(t => t.Uid, u => u.Date);
|
||||
}
|
||||
|
||||
public void SaveRequestDate(string uid)
|
||||
{
|
||||
public void SaveRequestDate(string uid) =>
|
||||
requests[uid] = DateTime.Now;
|
||||
DeleteOldRequestDates();
|
||||
}
|
||||
|
||||
public DateTime GetLastTelemetryDateByUid(string uid) =>
|
||||
requests.GetValueOrDefault(uid, DateTime.MinValue);
|
||||
|
||||
public IEnumerable<string> GetTransmittingTelemetryUids()
|
||||
{
|
||||
DeleteOldRequestDates();
|
||||
return requests.Keys;
|
||||
}
|
||||
|
||||
private void DeleteOldRequestDates() // TODO: удалить этот метод
|
||||
{
|
||||
requests = requests.Where(dValue => (DateTime.Now - dValue.Value) < timeout)
|
||||
.ToDictionary(dValue => dValue.Key, dValue => dValue.Value);
|
||||
}
|
||||
public IEnumerable<string> GetTransmittingTelemetryUids() =>
|
||||
requests.Keys;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user