Fixed cache issue.

This commit is contained in:
Roger Far 2021-06-05 14:56:16 -06:00
parent 71c9eb17fb
commit a3ea5c61f2
2 changed files with 92 additions and 115 deletions

View file

@ -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();
}
}
}

View file

@ -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
@ -95,10 +96,6 @@ 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
{
@ -116,21 +113,12 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
_torrentCache = null;
await VoidCache();
return torrent;
}
finally
{
_torrentCacheLock.Release();
}
}
public async Task UpdateRdData(Torrent torrent)
{
await _torrentCacheLock.WaitAsync();
try
{
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrent.TorrentId);
@ -158,19 +146,10 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
_torrentCache = null;
}
finally
{
_torrentCacheLock.Release();
}
await VoidCache();
}
public async Task UpdateCategory(Guid torrentId, String category)
{
await _torrentCacheLock.WaitAsync();
try
{
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
@ -183,19 +162,10 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
_torrentCache = null;
}
finally
{
_torrentCacheLock.Release();
}
await VoidCache();
}
public async Task UpdateComplete(Guid torrentId, DateTimeOffset? datetime)
{
await _torrentCacheLock.WaitAsync();
try
{
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
@ -203,19 +173,10 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
_torrentCache = null;
}
finally
{
_torrentCacheLock.Release();
}
await VoidCache();
}
public async Task Delete(Guid torrentId)
{
await _torrentCacheLock.WaitAsync();
try
{
var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId);
@ -228,6 +189,15 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await VoidCache();
}
public async Task VoidCache()
{
await _torrentCacheLock.WaitAsync();
try
{
_torrentCache = null;
}
finally