diff options
| author | Patrick Barron <barronpm@gmail.com> | 2020-10-03 21:14:25 -0400 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2020-10-04 20:29:28 -0400 |
| commit | 4d7e7d6331243bd339464bd6010569c6c308088b (patch) | |
| tree | 1751247cb72e2c41931157ea2a604fc7a5170cb2 /Jellyfin.Server.Implementations/Activity | |
| parent | c0be770681061d64436cd8176e5212526cef406a (diff) | |
Rewrite activity log backend to use a query class.
Diffstat (limited to 'Jellyfin.Server.Implementations/Activity')
| -rw-r--r-- | Jellyfin.Server.Implementations/Activity/ActivityManager.cs | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs index abdd290d4..695e2fbd8 100644 --- a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs +++ b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs @@ -3,8 +3,10 @@ using System.Linq; using System.Threading.Tasks; using Jellyfin.Data.Entities; using Jellyfin.Data.Events; +using Jellyfin.Data.Queries; using MediaBrowser.Model.Activity; using MediaBrowser.Model.Querying; +using Microsoft.EntityFrameworkCore; namespace Jellyfin.Server.Implementations.Activity { @@ -39,41 +41,34 @@ namespace Jellyfin.Server.Implementations.Activity } /// <inheritdoc/> - public QueryResult<ActivityLogEntry> GetPagedResult( - Func<IQueryable<ActivityLog>, IQueryable<ActivityLog>> func, - int? startIndex, - int? limit) + public async Task<QueryResult<ActivityLogEntry>> GetPagedResultAsync(ActivityLogQuery query) { - using var dbContext = _provider.CreateContext(); + await using var dbContext = _provider.CreateContext(); - var query = func(dbContext.ActivityLogs.OrderByDescending(entry => entry.DateCreated)); + IQueryable<ActivityLog> entries = dbContext.ActivityLogs.OrderByDescending(entry => entry.DateCreated); - if (startIndex.HasValue) + if (query.MinDate.HasValue) { - query = query.Skip(startIndex.Value); + entries = entries.Where(entry => entry.DateCreated >= query.MinDate); } - if (limit.HasValue) + if (query.HasUserId.HasValue) { - query = query.Take(limit.Value); + entries = entries.Where(entry => entry.UserId != Guid.Empty == query.HasUserId.Value ); } - // This converts the objects from the new database model to the old for compatibility with the existing API. - var list = query.Select(ConvertToOldModel).ToList(); - return new QueryResult<ActivityLogEntry> { - Items = list, - TotalRecordCount = func(dbContext.ActivityLogs).Count() + Items = await entries.Skip(query.StartIndex ?? 0) + .Take(query.Limit ?? 100) + .Select(ConvertToOldModel) + .AsQueryable() + .ToListAsync() + .ConfigureAwait(false), + TotalRecordCount = await entries.CountAsync().ConfigureAwait(false) }; } - /// <inheritdoc/> - public QueryResult<ActivityLogEntry> GetPagedResult(int? startIndex, int? limit) - { - return GetPagedResult(logs => logs, startIndex, limit); - } - private static ActivityLogEntry ConvertToOldModel(ActivityLog entry) { return new ActivityLogEntry |
