mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 01:24:44 +01:00
add bulk sync remove
This commit is contained in:
@@ -42,11 +42,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
_appHost = appHost;
|
||||
}
|
||||
|
||||
private string GetCachePath()
|
||||
{
|
||||
return Path.Combine(_appPaths.DataPath, "sync", _target.Id.GetMD5().ToString("N") + ".json");
|
||||
}
|
||||
|
||||
private string GetRemotePath()
|
||||
{
|
||||
var parts = new List<string>
|
||||
@@ -66,37 +61,17 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
return _fileSystem.GetValidFilename(filename);
|
||||
}
|
||||
|
||||
private async Task CacheData(Stream stream)
|
||||
{
|
||||
var cachePath = GetCachePath();
|
||||
|
||||
await _cacheFileLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
|
||||
using (var fileStream = _fileSystem.GetFileStream(cachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
||||
{
|
||||
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error saving sync data to {0}", ex, cachePath);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_cacheFileLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EnsureData(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_items == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = await _provider.GetFile(GetRemotePath(), _target, new Progress<double>(), cancellationToken))
|
||||
var path = GetRemotePath();
|
||||
|
||||
_logger.Debug("Getting {0} from {1}", path, _provider.Name);
|
||||
|
||||
using (var stream = await _provider.GetFile(path, _target, new Progress<double>(), cancellationToken))
|
||||
{
|
||||
_items = _json.DeserializeFromStream<List<LocalItem>>(stream);
|
||||
}
|
||||
@@ -109,15 +84,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
_items = new List<LocalItem>();
|
||||
}
|
||||
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
_json.SerializeToStream(_items, memoryStream);
|
||||
|
||||
// Now cache it
|
||||
memoryStream.Position = 0;
|
||||
await CacheData(memoryStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,10 +96,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
// Save to sync provider
|
||||
stream.Position = 0;
|
||||
await _provider.SendFile(stream, GetRemotePath(), _target, new Progress<double>(), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Now cache it
|
||||
stream.Position = 0;
|
||||
await CacheData(stream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,62 +166,14 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
return GetData(items => items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
private async Task<List<LocalItem>> GetCachedData()
|
||||
public Task<List<LocalItem>> GetItems(SyncTarget target, string serverId, string itemId)
|
||||
{
|
||||
if (_items == null)
|
||||
{
|
||||
await _cacheFileLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
if (_items == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_items = _json.DeserializeFromFile<List<LocalItem>>(GetCachePath());
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
_items = new List<LocalItem>();
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
_items = new List<LocalItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_cacheFileLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
return _items.ToList();
|
||||
return GetData(items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ItemId, itemId, StringComparison.OrdinalIgnoreCase)).ToList());
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetCachedServerItemIds(SyncTarget target, string serverId)
|
||||
public Task<List<LocalItem>> GetItemsBySyncJobItemId(SyncTarget target, string serverId, string syncJobItemId)
|
||||
{
|
||||
var items = await GetCachedData().ConfigureAwait(false);
|
||||
|
||||
return items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(i => i.ItemId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<LocalItem>> GetCachedItems(SyncTarget target, string serverId, string itemId)
|
||||
{
|
||||
var items = await GetCachedData().ConfigureAwait(false);
|
||||
|
||||
return items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ItemId, itemId, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<LocalItem>> GetCachedItemsBySyncJobItemId(SyncTarget target, string serverId, string syncJobItemId)
|
||||
{
|
||||
var items = await GetCachedData().ConfigureAwait(false);
|
||||
|
||||
return items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.SyncJobItemId, syncJobItemId, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
return GetData(items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.SyncJobItemId, syncJobItemId, StringComparison.OrdinalIgnoreCase)).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user