Apply more review suggestions
This commit is contained in:
parent
953777f1ba
commit
a5dee36808
|
@ -53,6 +53,7 @@ namespace Jellyfin.Data.Entities
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="type">The type.</param>
|
/// <param name="type">The type.</param>
|
||||||
/// <param name="userId">The user's id.</param>
|
/// <param name="userId">The user's id.</param>
|
||||||
|
/// <returns>The new <see cref="ActivityLog"/> instance.</returns>
|
||||||
public static ActivityLog Create(string name, string type, Guid userId)
|
public static ActivityLog Create(string name, string type, Guid userId)
|
||||||
{
|
{
|
||||||
return new ActivityLog(name, type, userId);
|
return new ActivityLog(name, type, userId);
|
||||||
|
@ -63,7 +64,7 @@ namespace Jellyfin.Data.Entities
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the identity of this instance.
|
/// Gets or sets the identity of this instance.
|
||||||
/// This is the key in the backing database.
|
/// This is the key in the backing database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Key]
|
[Key]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
|
@ -56,7 +55,7 @@ namespace Jellyfin.Server.Implementations.Activity
|
||||||
{
|
{
|
||||||
using var dbContext = _provider.CreateContext();
|
using var dbContext = _provider.CreateContext();
|
||||||
|
|
||||||
var query = func(dbContext.ActivityLogs).OrderByDescending(entry => entry.DateCreated).AsQueryable();
|
var query = func(dbContext.ActivityLogs.OrderByDescending(entry => entry.DateCreated));
|
||||||
|
|
||||||
if (startIndex.HasValue)
|
if (startIndex.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -69,12 +68,12 @@ namespace Jellyfin.Server.Implementations.Activity
|
||||||
}
|
}
|
||||||
|
|
||||||
// This converts the objects from the new database model to the old for compatibility with the existing API.
|
// This converts the objects from the new database model to the old for compatibility with the existing API.
|
||||||
var list = query.AsEnumerable().Select(ConvertToOldModel).ToList();
|
var list = query.Select(ConvertToOldModel).ToList();
|
||||||
|
|
||||||
return new QueryResult<ActivityLogEntry>
|
return new QueryResult<ActivityLogEntry>
|
||||||
{
|
{
|
||||||
Items = list,
|
Items = list,
|
||||||
TotalRecordCount = dbContext.ActivityLogs.Count()
|
TotalRecordCount = func(dbContext.ActivityLogs).Count()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,10 +107,11 @@ namespace Jellyfin.Server.Implementations
|
||||||
|
|
||||||
public override int SaveChanges()
|
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();
|
||||||
saveEntity?.OnSavingChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.SaveChanges();
|
return base.SaveChanges();
|
||||||
|
|
|
@ -12,9 +12,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||||
public JellyfinDb CreateDbContext(string[] args)
|
public JellyfinDb CreateDbContext(string[] args)
|
||||||
{
|
{
|
||||||
var optionsBuilder = new DbContextOptionsBuilder<JellyfinDb>();
|
var optionsBuilder = new DbContextOptionsBuilder<JellyfinDb>();
|
||||||
optionsBuilder.UseSqlite(
|
optionsBuilder.UseSqlite("Data Source=jellyfin.db");
|
||||||
"Data Source=jellyfin.db",
|
|
||||||
opt => opt.MigrationsAssembly("Jellyfin.Migrations"));
|
|
||||||
|
|
||||||
return new JellyfinDb(optionsBuilder.Options);
|
return new JellyfinDb(optionsBuilder.Options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,11 +106,10 @@ namespace Jellyfin.Server.Migrations.Routines
|
||||||
newEntry.ItemId = entry[5].ToString();
|
newEntry.ItemId = entry[5].ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since code references the Id of the entries, this needs to be inserted in order.
|
|
||||||
// In order to do that, we insert one by one because EF Core doesn't provide a way to guarantee ordering for bulk inserts.
|
|
||||||
dbContext.ActivityLogs.Add(newEntry);
|
dbContext.ActivityLogs.Add(newEntry);
|
||||||
dbContext.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
Loading…
Reference in New Issue
Block a user