aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2020-10-05 22:51:52 -0400
committerPatrick Barron <barronpm@gmail.com>2020-10-05 22:51:52 -0400
commitd4a492ef93f6b663fd4a4f7710613f06863f401f (patch)
tree9234b976f5fad5047e2ced7d86cf784f7aa4a278
parent4d7e7d6331243bd339464bd6010569c6c308088b (diff)
Fix activity log query.
-rw-r--r--Jellyfin.Server.Implementations/Activity/ActivityManager.cs9
-rw-r--r--Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj1
-rw-r--r--Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs1
-rw-r--r--Jellyfin.Server.Implementations/Users/UserManager.cs11
4 files changed, 14 insertions, 8 deletions
diff --git a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs
index 695e2fbd8..5926abfe0 100644
--- a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs
+++ b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs
@@ -45,7 +45,9 @@ namespace Jellyfin.Server.Implementations.Activity
{
await using var dbContext = _provider.CreateContext();
- IQueryable<ActivityLog> entries = dbContext.ActivityLogs.OrderByDescending(entry => entry.DateCreated);
+ IQueryable<ActivityLog> entries = dbContext.ActivityLogs
+ .AsQueryable()
+ .OrderByDescending(entry => entry.DateCreated);
if (query.MinDate.HasValue)
{
@@ -59,10 +61,11 @@ namespace Jellyfin.Server.Implementations.Activity
return new QueryResult<ActivityLogEntry>
{
- Items = await entries.Skip(query.StartIndex ?? 0)
+ Items = await entries
+ .Skip(query.StartIndex ?? 0)
.Take(query.Limit ?? 100)
+ .AsAsyncEnumerable()
.Select(ConvertToOldModel)
- .AsQueryable()
.ToListAsync()
.ConfigureAwait(false),
TotalRecordCount = await entries.CountAsync().ConfigureAwait(false)
diff --git a/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj b/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj
index 4e79dd8d6..17ba09258 100644
--- a/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj
+++ b/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj
@@ -24,6 +24,7 @@
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="System.Linq.Async" Version="4.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
index 46f1c618f..76f943385 100644
--- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
+++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
@@ -61,6 +61,7 @@ namespace Jellyfin.Server.Implementations.Users
public IList<ItemDisplayPreferences> ListItemDisplayPreferences(Guid userId, string client)
{
return _dbContext.ItemDisplayPreferences
+ .AsQueryable()
.Where(prefs => prefs.UserId == userId && prefs.ItemId != Guid.Empty && string.Equals(prefs.Client, client))
.ToList();
}
diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.cs
index 8f04baa08..8f6a0496a 100644
--- a/Jellyfin.Server.Implementations/Users/UserManager.cs
+++ b/Jellyfin.Server.Implementations/Users/UserManager.cs
@@ -108,6 +108,7 @@ namespace Jellyfin.Server.Implementations.Users
{
using var dbContext = _dbProvider.CreateContext();
return dbContext.Users
+ .AsQueryable()
.Select(user => user.Id)
.ToList();
}
@@ -200,8 +201,8 @@ namespace Jellyfin.Server.Implementations.Users
internal async Task<User> CreateUserInternalAsync(string name, JellyfinDb dbContext)
{
// TODO: Remove after user item data is migrated.
- var max = await dbContext.Users.AnyAsync().ConfigureAwait(false)
- ? await dbContext.Users.Select(u => u.InternalId).MaxAsync().ConfigureAwait(false)
+ var max = await dbContext.Users.AsQueryable().AnyAsync().ConfigureAwait(false)
+ ? await dbContext.Users.AsQueryable().Select(u => u.InternalId).MaxAsync().ConfigureAwait(false)
: 0;
return new User(
@@ -221,7 +222,7 @@ namespace Jellyfin.Server.Implementations.Users
throw new ArgumentException("Usernames can contain unicode symbols, numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)");
}
- using var dbContext = _dbProvider.CreateContext();
+ await using var dbContext = _dbProvider.CreateContext();
var newUser = await CreateUserInternalAsync(name, dbContext).ConfigureAwait(false);
@@ -587,9 +588,9 @@ namespace Jellyfin.Server.Implementations.Users
public async Task InitializeAsync()
{
// TODO: Refactor the startup wizard so that it doesn't require a user to already exist.
- using var dbContext = _dbProvider.CreateContext();
+ await using var dbContext = _dbProvider.CreateContext();
- if (await dbContext.Users.AnyAsync().ConfigureAwait(false))
+ if (await dbContext.Users.AsQueryable().AnyAsync().ConfigureAwait(false))
{
return;
}