aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2020-05-15 17:20:07 -0400
committerPatrick Barron <barronpm@gmail.com>2020-05-15 17:20:07 -0400
commitaca7e221d811040bdb14da6390bbd16c5f7db785 (patch)
tree87c77521066511890e236a97afb27a475f32c0a3 /Jellyfin.Server.Implementations
parentb7621d762c58320b35096838ae8ab10d98ea9bb2 (diff)
parent652e9702fc67784fd11e26ee159f31e6f0ba9dd7 (diff)
Merge branch 'master' into userdb-efcore
# Conflicts: # Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs # Emby.Server.Implementations/ApplicationHost.cs # Emby.Server.Implementations/Devices/DeviceManager.cs # Jellyfin.Server/Jellyfin.Server.csproj # Jellyfin.Server/Migrations/MigrationRunner.cs # MediaBrowser.Controller/Devices/IDeviceManager.cs
Diffstat (limited to 'Jellyfin.Server.Implementations')
-rw-r--r--Jellyfin.Server.Implementations/Activity/ActivityManager.cs17
-rw-r--r--Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj8
-rw-r--r--Jellyfin.Server.Implementations/JellyfinDb.cs5
-rw-r--r--Jellyfin.Server.Implementations/JellyfinDbProvider.cs2
-rw-r--r--Jellyfin.Server.Implementations/Migrations/20200514181226_AddActivityLog.Designer.cs (renamed from Jellyfin.Server.Implementations/Migrations/20200502231229_InitialSchema.Designer.cs)9
-rw-r--r--Jellyfin.Server.Implementations/Migrations/20200514181226_AddActivityLog.cs (renamed from Jellyfin.Server.Implementations/Migrations/20200502231229_InitialSchema.cs)10
-rw-r--r--Jellyfin.Server.Implementations/Migrations/DesignTimeJellyfinDbFactory.cs3
-rw-r--r--Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs4
8 files changed, 30 insertions, 28 deletions
diff --git a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs
index d7bbf793c4..65ceee32bf 100644
--- a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs
+++ b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
@@ -14,7 +13,7 @@ namespace Jellyfin.Server.Implementations.Activity
/// </summary>
public class ActivityManager : IActivityManager
{
- private JellyfinDbProvider _provider;
+ private readonly JellyfinDbProvider _provider;
/// <summary>
/// Initializes a new instance of the <see cref="ActivityManager"/> class.
@@ -50,31 +49,31 @@ namespace Jellyfin.Server.Implementations.Activity
/// <inheritdoc/>
public QueryResult<ActivityLogEntry> GetPagedResult(
- Func<IQueryable<ActivityLog>, IEnumerable<ActivityLog>> func,
+ Func<IQueryable<ActivityLog>, IQueryable<ActivityLog>> func,
int? startIndex,
int? limit)
{
using var dbContext = _provider.CreateContext();
- var result = func.Invoke(dbContext.ActivityLogs).AsQueryable();
+ var query = func(dbContext.ActivityLogs.OrderByDescending(entry => entry.DateCreated));
if (startIndex.HasValue)
{
- result = result.Where(entry => entry.Id >= startIndex.Value);
+ query = query.Skip(startIndex.Value);
}
if (limit.HasValue)
{
- result = result.OrderByDescending(entry => entry.DateCreated).Take(limit.Value);
+ query = query.Take(limit.Value);
}
// This converts the objects from the new database model to the old for compatibility with the existing API.
- var list = result.Select(entry => ConvertToOldModel(entry)).ToList();
+ var list = query.Select(ConvertToOldModel).ToList();
- return new QueryResult<ActivityLogEntry>()
+ return new QueryResult<ActivityLogEntry>
{
Items = list,
- TotalRecordCount = list.Count
+ TotalRecordCount = func(dbContext.ActivityLogs).Count()
};
}
diff --git a/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj b/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj
index 7ff9786980..09310f98c6 100644
--- a/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj
+++ b/Jellyfin.Server.Implementations/Jellyfin.Server.Implementations.csproj
@@ -28,6 +28,14 @@
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3">
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ </PackageReference>
+ </ItemGroup>
+
+ <ItemGroup>
<ProjectReference Include="..\Jellyfin.Data\Jellyfin.Data.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
diff --git a/Jellyfin.Server.Implementations/JellyfinDb.cs b/Jellyfin.Server.Implementations/JellyfinDb.cs
index 35003c1ae3..9ac97a131b 100644
--- a/Jellyfin.Server.Implementations/JellyfinDb.cs
+++ b/Jellyfin.Server.Implementations/JellyfinDb.cs
@@ -107,9 +107,10 @@ namespace Jellyfin.Server.Implementations
public override int SaveChanges()
{
- foreach (var entity in ChangeTracker.Entries().Where(e => e.State == EntityState.Modified))
+ foreach (var saveEntity in ChangeTracker.Entries()
+ .Where(e => e.State == EntityState.Modified)
+ .OfType<ISavingChanges>())
{
- var saveEntity = entity.Entity as ISavingChanges;
saveEntity.OnSavingChanges();
}
diff --git a/Jellyfin.Server.Implementations/JellyfinDbProvider.cs b/Jellyfin.Server.Implementations/JellyfinDbProvider.cs
index 8fdeab0887..eab531d386 100644
--- a/Jellyfin.Server.Implementations/JellyfinDbProvider.cs
+++ b/Jellyfin.Server.Implementations/JellyfinDbProvider.cs
@@ -27,7 +27,7 @@ namespace Jellyfin.Server.Implementations
/// <returns>The newly created context.</returns>
public JellyfinDb CreateContext()
{
- return _serviceProvider.GetService<JellyfinDb>();
+ return _serviceProvider.GetRequiredService<JellyfinDb>();
}
}
}
diff --git a/Jellyfin.Server.Implementations/Migrations/20200502231229_InitialSchema.Designer.cs b/Jellyfin.Server.Implementations/Migrations/20200514181226_AddActivityLog.Designer.cs
index e1ee9b34aa..98a83b7450 100644
--- a/Jellyfin.Server.Implementations/Migrations/20200502231229_InitialSchema.Designer.cs
+++ b/Jellyfin.Server.Implementations/Migrations/20200514181226_AddActivityLog.Designer.cs
@@ -1,5 +1,4 @@
-#pragma warning disable CS1591
-#pragma warning disable SA1601
+#pragma warning disable CS1591
// <auto-generated />
using System;
@@ -12,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Jellyfin.Server.Implementations.Migrations
{
[DbContext(typeof(JellyfinDb))]
- [Migration("20200502231229_InitialSchema")]
- partial class InitialSchema
+ [Migration("20200514181226_AddActivityLog")]
+ partial class AddActivityLog
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@@ -65,7 +64,7 @@ namespace Jellyfin.Server.Implementations.Migrations
b.HasKey("Id");
- b.ToTable("ActivityLog");
+ b.ToTable("ActivityLogs");
});
#pragma warning restore 612, 618
}
diff --git a/Jellyfin.Server.Implementations/Migrations/20200502231229_InitialSchema.cs b/Jellyfin.Server.Implementations/Migrations/20200514181226_AddActivityLog.cs
index 42fac865ce..5e0b454d8b 100644
--- a/Jellyfin.Server.Implementations/Migrations/20200502231229_InitialSchema.cs
+++ b/Jellyfin.Server.Implementations/Migrations/20200514181226_AddActivityLog.cs
@@ -1,4 +1,4 @@
-#pragma warning disable CS1591
+#pragma warning disable CS1591
#pragma warning disable SA1601
using System;
@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Jellyfin.Server.Implementations.Migrations
{
- public partial class InitialSchema : Migration
+ public partial class AddActivityLog : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@@ -14,7 +14,7 @@ namespace Jellyfin.Server.Implementations.Migrations
name: "jellyfin");
migrationBuilder.CreateTable(
- name: "ActivityLog",
+ name: "ActivityLogs",
schema: "jellyfin",
columns: table => new
{
@@ -32,14 +32,14 @@ namespace Jellyfin.Server.Implementations.Migrations
},
constraints: table =>
{
- table.PrimaryKey("PK_ActivityLog", x => x.Id);
+ table.PrimaryKey("PK_ActivityLogs", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
- name: "ActivityLog",
+ name: "ActivityLogs",
schema: "jellyfin");
}
}
diff --git a/Jellyfin.Server.Implementations/Migrations/DesignTimeJellyfinDbFactory.cs b/Jellyfin.Server.Implementations/Migrations/DesignTimeJellyfinDbFactory.cs
index 23a0fdc784..72a4a8c3b6 100644
--- a/Jellyfin.Server.Implementations/Migrations/DesignTimeJellyfinDbFactory.cs
+++ b/Jellyfin.Server.Implementations/Migrations/DesignTimeJellyfinDbFactory.cs
@@ -1,6 +1,3 @@
-#pragma warning disable CS1591
-#pragma warning disable SA1601
-
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
diff --git a/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs b/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs
index d3a7ed3334..0fb0ba8033 100644
--- a/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs
+++ b/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs
@@ -1,9 +1,7 @@
// <auto-generated />
using System;
-using Jellyfin.Server.Implementations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Jellyfin.Server.Implementations.Migrations
{
@@ -60,7 +58,7 @@ namespace Jellyfin.Server.Implementations.Migrations
b.HasKey("Id");
- b.ToTable("ActivityLog");
+ b.ToTable("ActivityLogs");
});
modelBuilder.Entity("Jellyfin.Data.Entities.Group", b =>