diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs b/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs index 787cbcc5b..f491a5c44 100644 --- a/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs +++ b/MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs @@ -139,7 +139,7 @@ namespace MediaBrowser.Server.Implementations.Activity } } - public QueryResult<ActivityLogEntry> GetActivityLogEntries(int? startIndex, int? limit) + public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit) { using (var cmd = _connection.CreateCommand()) { @@ -147,17 +147,33 @@ namespace MediaBrowser.Server.Implementations.Activity var whereClauses = new List<string>(); - if (startIndex.HasValue && startIndex.Value > 0) + if (minDate.HasValue) { - whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLogEntries ORDER BY DateCreated DESC LIMIT {0})", - startIndex.Value.ToString(_usCulture))); + whereClauses.Add("DateCreated>=@DateCreated"); + cmd.Parameters.Add(cmd, "@DateCreated", DbType.Date).Value = minDate.Value; } - if (whereClauses.Count > 0) + var whereTextWithoutPaging = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + if (startIndex.HasValue && startIndex.Value > 0) { - cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray()); + var pagingWhereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLogEntries {0} ORDER BY DateCreated DESC LIMIT {1})", + pagingWhereText, + startIndex.Value.ToString(_usCulture))); } + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + cmd.CommandText += whereText; + cmd.CommandText += " ORDER BY DateCreated DESC"; if (limit.HasValue) @@ -165,7 +181,7 @@ namespace MediaBrowser.Server.Implementations.Activity cmd.CommandText += " LIMIT " + limit.Value.ToString(_usCulture); } - cmd.CommandText += "; select count (Id) from ActivityLogEntries"; + cmd.CommandText += "; select count (Id) from ActivityLogEntries" + whereTextWithoutPaging; var list = new List<ActivityLogEntry>(); var count = 0; |
