Fixed cache issue.
This commit is contained in:
parent
71c9eb17fb
commit
a3ea5c61f2
2 changed files with 92 additions and 115 deletions
|
|
@ -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 Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
@ -27,26 +26,12 @@ namespace RdtClient.Data.Data
|
||||||
public class DownloadData : IDownloadData
|
public class DownloadData : IDownloadData
|
||||||
{
|
{
|
||||||
private readonly DataContext _dataContext;
|
private readonly DataContext _dataContext;
|
||||||
|
private readonly ITorrentData _torrentData;
|
||||||
|
|
||||||
public DownloadData(DataContext dataContext)
|
public DownloadData(DataContext dataContext, ITorrentData torrentData)
|
||||||
{
|
{
|
||||||
_dataContext = dataContext;
|
_dataContext = dataContext;
|
||||||
}
|
_torrentData = torrentData;
|
||||||
|
|
||||||
public async Task<IList<Download>> Get()
|
|
||||||
{
|
|
||||||
return await _dataContext.Downloads
|
|
||||||
.AsNoTracking()
|
|
||||||
.Include(m => m.Torrent)
|
|
||||||
.ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IList<Download>> GetForTorrent(Guid torrentId)
|
|
||||||
{
|
|
||||||
return await _dataContext.Downloads
|
|
||||||
.AsNoTracking()
|
|
||||||
.Where(m => m.TorrentId == torrentId)
|
|
||||||
.ToListAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Download> GetById(Guid downloadId)
|
public async Task<Download> GetById(Guid downloadId)
|
||||||
|
|
@ -78,6 +63,8 @@ namespace RdtClient.Data.Data
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
|
|
||||||
return download;
|
return download;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,6 +76,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.Link = unrestrictedLink;
|
dbDownload.Link = unrestrictedLink;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime)
|
public async Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime)
|
||||||
|
|
@ -99,6 +88,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.DownloadStarted = dateTime;
|
dbDownload.DownloadStarted = dateTime;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateDownloadFinished(Guid downloadId, DateTimeOffset? dateTime)
|
public async Task UpdateDownloadFinished(Guid downloadId, DateTimeOffset? dateTime)
|
||||||
|
|
@ -114,6 +105,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.DownloadFinished = dateTime;
|
dbDownload.DownloadFinished = dateTime;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime)
|
public async Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime)
|
||||||
|
|
@ -124,6 +117,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.UnpackingQueued = dateTime;
|
dbDownload.UnpackingQueued = dateTime;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime)
|
public async Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime)
|
||||||
|
|
@ -134,6 +129,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.UnpackingStarted = dateTime;
|
dbDownload.UnpackingStarted = dateTime;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime)
|
public async Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime)
|
||||||
|
|
@ -144,6 +141,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.UnpackingFinished = dateTime;
|
dbDownload.UnpackingFinished = dateTime;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime)
|
public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime)
|
||||||
|
|
@ -154,6 +153,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.Completed = dateTime;
|
dbDownload.Completed = dateTime;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateError(Guid downloadId, String error)
|
public async Task UpdateError(Guid downloadId, String error)
|
||||||
|
|
@ -164,6 +165,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.Error = error;
|
dbDownload.Error = error;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateRetryCount(Guid downloadId, Int32 retryCount)
|
public async Task UpdateRetryCount(Guid downloadId, Int32 retryCount)
|
||||||
|
|
@ -174,6 +177,8 @@ namespace RdtClient.Data.Data
|
||||||
dbDownload.RetryCount = retryCount;
|
dbDownload.RetryCount = retryCount;
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteForTorrent(Guid torrentId)
|
public async Task DeleteForTorrent(Guid torrentId)
|
||||||
|
|
@ -185,6 +190,8 @@ namespace RdtClient.Data.Data
|
||||||
_dataContext.Downloads.RemoveRange(downloads);
|
_dataContext.Downloads.RemoveRange(downloads);
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _torrentData.VoidCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ namespace RdtClient.Data.Data
|
||||||
Task UpdateCategory(Guid torrentId, String category);
|
Task UpdateCategory(Guid torrentId, String category);
|
||||||
Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime);
|
Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime);
|
||||||
Task Delete(Guid torrentId);
|
Task Delete(Guid torrentId);
|
||||||
|
Task VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TorrentData : ITorrentData
|
public class TorrentData : ITorrentData
|
||||||
|
|
@ -96,138 +97,107 @@ namespace RdtClient.Data.Data
|
||||||
|
|
||||||
public async Task<Torrent> Add(String realDebridId, String hash, String category, Boolean autoDelete, String fileOrMagnetContents, Boolean isFile)
|
public async Task<Torrent> Add(String realDebridId, String hash, String category, Boolean autoDelete, String fileOrMagnetContents, Boolean isFile)
|
||||||
{
|
{
|
||||||
await _torrentCacheLock.WaitAsync();
|
var torrent = new Torrent
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var torrent = new Torrent
|
TorrentId = Guid.NewGuid(),
|
||||||
{
|
Added = DateTimeOffset.UtcNow,
|
||||||
TorrentId = Guid.NewGuid(),
|
RdId = realDebridId,
|
||||||
Added = DateTimeOffset.UtcNow,
|
Hash = hash.ToLower(),
|
||||||
RdId = realDebridId,
|
Category = category,
|
||||||
Hash = hash.ToLower(),
|
AutoDelete = autoDelete,
|
||||||
Category = category,
|
FileOrMagnet = fileOrMagnetContents,
|
||||||
AutoDelete = autoDelete,
|
IsFile = isFile
|
||||||
FileOrMagnet = fileOrMagnetContents,
|
};
|
||||||
IsFile = isFile
|
|
||||||
};
|
|
||||||
|
|
||||||
await _dataContext.Torrents.AddAsync(torrent);
|
await _dataContext.Torrents.AddAsync(torrent);
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
_torrentCache = null;
|
await VoidCache();
|
||||||
|
|
||||||
return torrent;
|
return torrent;
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_torrentCacheLock.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateRdData(Torrent torrent)
|
public async Task UpdateRdData(Torrent torrent)
|
||||||
{
|
{
|
||||||
await _torrentCacheLock.WaitAsync();
|
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrent.TorrentId);
|
||||||
|
|
||||||
try
|
if (dbTorrent == null)
|
||||||
{
|
{
|
||||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrent.TorrentId);
|
return;
|
||||||
|
|
||||||
if (dbTorrent == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbTorrent.RdName = torrent.RdName;
|
|
||||||
dbTorrent.RdSize = torrent.RdSize;
|
|
||||||
dbTorrent.RdHost = torrent.RdHost;
|
|
||||||
dbTorrent.RdSplit = torrent.RdSplit;
|
|
||||||
dbTorrent.RdProgress = torrent.RdProgress;
|
|
||||||
dbTorrent.RdStatus = torrent.RdStatus;
|
|
||||||
dbTorrent.RdStatusRaw = torrent.RdStatusRaw;
|
|
||||||
dbTorrent.RdAdded = torrent.RdAdded;
|
|
||||||
dbTorrent.RdEnded = torrent.RdEnded;
|
|
||||||
dbTorrent.RdSpeed = torrent.RdSpeed;
|
|
||||||
dbTorrent.RdSeeders = torrent.RdSeeders;
|
|
||||||
|
|
||||||
if (torrent.Files != null)
|
|
||||||
{
|
|
||||||
dbTorrent.RdFiles = torrent.RdFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
_torrentCache = null;
|
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
|
dbTorrent.RdName = torrent.RdName;
|
||||||
|
dbTorrent.RdSize = torrent.RdSize;
|
||||||
|
dbTorrent.RdHost = torrent.RdHost;
|
||||||
|
dbTorrent.RdSplit = torrent.RdSplit;
|
||||||
|
dbTorrent.RdProgress = torrent.RdProgress;
|
||||||
|
dbTorrent.RdStatus = torrent.RdStatus;
|
||||||
|
dbTorrent.RdStatusRaw = torrent.RdStatusRaw;
|
||||||
|
dbTorrent.RdAdded = torrent.RdAdded;
|
||||||
|
dbTorrent.RdEnded = torrent.RdEnded;
|
||||||
|
dbTorrent.RdSpeed = torrent.RdSpeed;
|
||||||
|
dbTorrent.RdSeeders = torrent.RdSeeders;
|
||||||
|
|
||||||
|
if (torrent.Files != null)
|
||||||
{
|
{
|
||||||
_torrentCacheLock.Release();
|
dbTorrent.RdFiles = torrent.RdFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateCategory(Guid torrentId, String category)
|
public async Task UpdateCategory(Guid torrentId, String category)
|
||||||
{
|
{
|
||||||
await _torrentCacheLock.WaitAsync();
|
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
||||||
|
|
||||||
try
|
if (dbTorrent == null)
|
||||||
{
|
{
|
||||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
return;
|
||||||
|
|
||||||
if (dbTorrent == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbTorrent.Category = category;
|
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
_torrentCache = null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_torrentCacheLock.Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbTorrent.Category = category;
|
||||||
|
|
||||||
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await VoidCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime)
|
public async Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime)
|
||||||
{
|
{
|
||||||
await _torrentCacheLock.WaitAsync();
|
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
||||||
|
|
||||||
try
|
dbTorrent.Completed = datetime;
|
||||||
{
|
|
||||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
|
||||||
|
|
||||||
dbTorrent.Completed = datetime;
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
await VoidCache();
|
||||||
|
|
||||||
_torrentCache = null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_torrentCacheLock.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Delete(Guid torrentId)
|
public async Task Delete(Guid torrentId)
|
||||||
|
{
|
||||||
|
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
||||||
|
|
||||||
|
if (dbTorrent == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_dataContext.Torrents.Remove(dbTorrent);
|
||||||
|
|
||||||
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
await VoidCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task VoidCache()
|
||||||
{
|
{
|
||||||
await _torrentCacheLock.WaitAsync();
|
await _torrentCacheLock.WaitAsync();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
|
||||||
|
|
||||||
if (dbTorrent == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_dataContext.Torrents.Remove(dbTorrent);
|
|
||||||
|
|
||||||
await _dataContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
_torrentCache = null;
|
_torrentCache = null;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue