mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fixed trimming retention period interpretation.
When the retention period was set to 0, the events would not be deleted until after 1 day. This has been fixed by taking the last hour of the current day and subtracting the retention period from that value, and then doing an "inclusive less than" check.
This commit is contained in:
@@ -6,8 +6,11 @@ namespace Orchard.AuditTrail.Helpers {
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
var v = value.Value;
|
||||
return new DateTime(v.Year, v.Month, v.Day, 0, 0, 0, 0, v.Kind);
|
||||
return Earliest(value.Value);
|
||||
}
|
||||
|
||||
public static DateTime Earliest(this DateTime value) {
|
||||
return new DateTime(value.Year, value.Month, value.Day, 0, 0, 0, 0, value.Kind);
|
||||
}
|
||||
|
||||
public static DateTime? Latest(this DateTime? value) {
|
||||
@@ -17,5 +20,9 @@ namespace Orchard.AuditTrail.Helpers {
|
||||
var v = value.Value;
|
||||
return new DateTime(v.Year, v.Month, v.Day, 23, 59, 59, 999, v.Kind);
|
||||
}
|
||||
|
||||
public static DateTime Latest(this DateTime value) {
|
||||
return new DateTime(value.Year, value.Month, value.Day, 23, 59, 59, 999, value.Kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,8 +207,8 @@ namespace Orchard.AuditTrail.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod) {
|
||||
var dateThreshold = _clock.UtcNow.Date - retentionPeriod;
|
||||
var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc < dateThreshold);
|
||||
var dateThreshold = (_clock.UtcNow.Latest() - retentionPeriod);
|
||||
var query = _auditTrailRepository.Table.Where(x => x.CreatedUtc <= dateThreshold);
|
||||
var records = query.ToArray();
|
||||
|
||||
foreach (var record in records) {
|
||||
|
||||
Reference in New Issue
Block a user