mirror of https://github.com/lidarr/Lidarr
Many (update/insert/delete) DB operations now use transactions
Fixed: Improved series/episode info refresh speed
This commit is contained in:
parent
36387dd13f
commit
0a837be9ff
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.UI.WebControls;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Marr.Data;
|
||||
using Marr.Data.QGen;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
|
@ -142,23 +143,44 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
public void InsertMany(IList<TModel> models)
|
||||
{
|
||||
foreach (var model in models)
|
||||
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
||||
{
|
||||
Insert(model);
|
||||
unitOfWork.BeginTransaction();
|
||||
|
||||
foreach (var model in models)
|
||||
{
|
||||
unitOfWork.DB.Insert(model);
|
||||
}
|
||||
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMany(IList<TModel> models)
|
||||
{
|
||||
foreach (var model in models)
|
||||
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
||||
{
|
||||
Update(model);
|
||||
unitOfWork.BeginTransaction();
|
||||
|
||||
foreach (var model in models)
|
||||
{
|
||||
var localModel = model;
|
||||
|
||||
if (model.Id == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Can't update model with ID 0");
|
||||
}
|
||||
|
||||
unitOfWork.DB.Update(model, c => c.Id == localModel.Id);
|
||||
}
|
||||
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteMany(List<TModel> models)
|
||||
{
|
||||
models.ForEach(Delete);
|
||||
DeleteMany(models.Select(m => m.Id));
|
||||
}
|
||||
|
||||
public TModel Upsert(TModel model)
|
||||
|
@ -179,7 +201,19 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
public void DeleteMany(IEnumerable<int> ids)
|
||||
{
|
||||
ids.ToList().ForEach(Delete);
|
||||
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
||||
{
|
||||
unitOfWork.BeginTransaction();
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var localId = id;
|
||||
|
||||
unitOfWork.DB.Delete<TModel>(c => c.Id == localId);
|
||||
}
|
||||
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
public void Purge()
|
||||
|
|
Loading…
Reference in New Issue