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