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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
@ -27,26 +26,12 @@ namespace RdtClient.Data.Data
|
|||
public class DownloadData : IDownloadData
|
||||
{
|
||||
private readonly DataContext _dataContext;
|
||||
private readonly ITorrentData _torrentData;
|
||||
|
||||
public DownloadData(DataContext dataContext)
|
||||
public DownloadData(DataContext dataContext, ITorrentData torrentData)
|
||||
{
|
||||
_dataContext = dataContext;
|
||||
}
|
||||
|
||||
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();
|
||||
_torrentData = torrentData;
|
||||
}
|
||||
|
||||
public async Task<Download> GetById(Guid downloadId)
|
||||
|
|
@ -78,6 +63,8 @@ namespace RdtClient.Data.Data
|
|||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
|
||||
return download;
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +76,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.Link = unrestrictedLink;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime)
|
||||
|
|
@ -99,6 +88,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.DownloadStarted = dateTime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateDownloadFinished(Guid downloadId, DateTimeOffset? dateTime)
|
||||
|
|
@ -114,6 +105,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.DownloadFinished = dateTime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime)
|
||||
|
|
@ -124,6 +117,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.UnpackingQueued = dateTime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime)
|
||||
|
|
@ -134,6 +129,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.UnpackingStarted = dateTime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime)
|
||||
|
|
@ -144,6 +141,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.UnpackingFinished = dateTime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime)
|
||||
|
|
@ -154,6 +153,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.Completed = dateTime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateError(Guid downloadId, String error)
|
||||
|
|
@ -164,6 +165,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.Error = error;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateRetryCount(Guid downloadId, Int32 retryCount)
|
||||
|
|
@ -174,6 +177,8 @@ namespace RdtClient.Data.Data
|
|||
dbDownload.RetryCount = retryCount;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
|
||||
public async Task DeleteForTorrent(Guid torrentId)
|
||||
|
|
@ -185,6 +190,8 @@ namespace RdtClient.Data.Data
|
|||
_dataContext.Downloads.RemoveRange(downloads);
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await _torrentData.VoidCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ namespace RdtClient.Data.Data
|
|||
Task UpdateCategory(Guid torrentId, String category);
|
||||
Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime);
|
||||
Task Delete(Guid torrentId);
|
||||
Task VoidCache();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
await _torrentCacheLock.WaitAsync();
|
||||
|
||||
try
|
||||
var torrent = new Torrent
|
||||
{
|
||||
var torrent = new Torrent
|
||||
{
|
||||
TorrentId = Guid.NewGuid(),
|
||||
Added = DateTimeOffset.UtcNow,
|
||||
RdId = realDebridId,
|
||||
Hash = hash.ToLower(),
|
||||
Category = category,
|
||||
AutoDelete = autoDelete,
|
||||
FileOrMagnet = fileOrMagnetContents,
|
||||
IsFile = isFile
|
||||
};
|
||||
TorrentId = Guid.NewGuid(),
|
||||
Added = DateTimeOffset.UtcNow,
|
||||
RdId = realDebridId,
|
||||
Hash = hash.ToLower(),
|
||||
Category = category,
|
||||
AutoDelete = autoDelete,
|
||||
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;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_torrentCacheLock.Release();
|
||||
}
|
||||
return 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);
|
||||
|
||||
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;
|
||||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
if (dbTorrent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dbTorrent.Category = category;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
_torrentCache = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_torrentCacheLock.Release();
|
||||
return;
|
||||
}
|
||||
|
||||
dbTorrent.Category = category;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await VoidCache();
|
||||
}
|
||||
|
||||
public async Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime)
|
||||
{
|
||||
await _torrentCacheLock.WaitAsync();
|
||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
||||
|
||||
try
|
||||
{
|
||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
||||
dbTorrent.Completed = datetime;
|
||||
|
||||
dbTorrent.Completed = datetime;
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
_torrentCache = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_torrentCacheLock.Release();
|
||||
}
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
await VoidCache();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
try
|
||||
{
|
||||
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
|
||||
|
||||
if (dbTorrent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_dataContext.Torrents.Remove(dbTorrent);
|
||||
|
||||
await _dataContext.SaveChangesAsync();
|
||||
|
||||
_torrentCache = null;
|
||||
}
|
||||
finally
|
||||
|
|
|
|||
Loading…
Reference in a new issue