mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 22:38:30 +01:00
fixes #223 - New Content Localhost Popups Repeat 'Old' 'New Content' on Media Changes
This commit is contained in:
@@ -103,7 +103,8 @@ namespace MediaBrowser.Server.Implementations.IO
|
||||
/// </summary>
|
||||
public void Start()
|
||||
{
|
||||
LibraryManager.LibraryChanged += Instance_LibraryChanged;
|
||||
LibraryManager.ItemAdded += LibraryManager_ItemAdded;
|
||||
LibraryManager.ItemRemoved += LibraryManager_ItemRemoved;
|
||||
|
||||
var pathsToWatch = new List<string> { LibraryManager.RootFolder.Path };
|
||||
|
||||
@@ -137,6 +138,32 @@ namespace MediaBrowser.Server.Implementations.IO
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the ItemRemoved event of the LibraryManager control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
|
||||
void LibraryManager_ItemRemoved(object sender, ItemChangeEventArgs e)
|
||||
{
|
||||
if (e.Item.Parent is AggregateFolder)
|
||||
{
|
||||
StopWatchingPath(e.Item.Path);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the ItemAdded event of the LibraryManager control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
|
||||
void LibraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
|
||||
{
|
||||
if (e.Item.Parent is AggregateFolder)
|
||||
{
|
||||
StartWatchingPath(e.Item.Path);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Examine a list of strings assumed to be file paths to see if it contains a parent of
|
||||
/// the provided path.
|
||||
@@ -231,32 +258,6 @@ namespace MediaBrowser.Server.Implementations.IO
|
||||
_fileSystemWatchers = new ConcurrentBag<FileSystemWatcher>(watchers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the LibraryChanged event of the Kernel
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="MediaBrowser.Controller.Library.ChildrenChangedEventArgs" /> instance containing the event data.</param>
|
||||
void Instance_LibraryChanged(object sender, ChildrenChangedEventArgs e)
|
||||
{
|
||||
if (e.Folder is AggregateFolder && e.HasAddOrRemoveChange)
|
||||
{
|
||||
if (e.ItemsRemoved != null)
|
||||
{
|
||||
foreach (var item in e.ItemsRemoved.OfType<Folder>())
|
||||
{
|
||||
StopWatchingPath(item.Path);
|
||||
}
|
||||
}
|
||||
if (e.ItemsAdded != null)
|
||||
{
|
||||
foreach (var item in e.ItemsAdded.OfType<Folder>())
|
||||
{
|
||||
StartWatchingPath(item.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the Error event of the watcher control.
|
||||
/// </summary>
|
||||
@@ -497,7 +498,8 @@ namespace MediaBrowser.Server.Implementations.IO
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
LibraryManager.LibraryChanged -= Instance_LibraryChanged;
|
||||
LibraryManager.ItemAdded -= LibraryManager_ItemAdded;
|
||||
LibraryManager.ItemRemoved -= LibraryManager_ItemRemoved;
|
||||
|
||||
FileSystemWatcher watcher;
|
||||
|
||||
|
||||
@@ -69,24 +69,20 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <value>The item repository.</value>
|
||||
public IItemRepository ItemRepository { get; set; }
|
||||
|
||||
#region LibraryChanged Event
|
||||
/// <summary>
|
||||
/// Fires whenever any validation routine adds or removes items. The added and removed items are properties of the args.
|
||||
/// *** Will fire asynchronously. ***
|
||||
/// Occurs when [item added].
|
||||
/// </summary>
|
||||
public event EventHandler<ChildrenChangedEventArgs> LibraryChanged;
|
||||
public event EventHandler<ItemChangeEventArgs> ItemAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Reports the library changed.
|
||||
/// Occurs when [item updated].
|
||||
/// </summary>
|
||||
/// <param name="args">The <see cref="ChildrenChangedEventArgs" /> instance containing the event data.</param>
|
||||
public void ReportLibraryChanged(ChildrenChangedEventArgs args)
|
||||
{
|
||||
UpdateLibraryCache(args);
|
||||
public event EventHandler<ItemChangeEventArgs> ItemUpdated;
|
||||
|
||||
EventHelper.FireEventIfNotNull(LibraryChanged, this, args, _logger);
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Occurs when [item removed].
|
||||
/// </summary>
|
||||
public event EventHandler<ItemChangeEventArgs> ItemRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// The _logger
|
||||
@@ -302,25 +298,6 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
return new ConcurrentDictionary<Guid, BaseItem>(items.ToDictionary(i => i.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the library cache.
|
||||
/// </summary>
|
||||
/// <param name="args">The <see cref="ChildrenChangedEventArgs"/> instance containing the event data.</param>
|
||||
private void UpdateLibraryCache(ChildrenChangedEventArgs args)
|
||||
{
|
||||
UpdateItemInLibraryCache(args.Folder);
|
||||
|
||||
foreach (var item in args.ItemsAdded)
|
||||
{
|
||||
UpdateItemInLibraryCache(item);
|
||||
}
|
||||
|
||||
foreach (var item in args.ItemsUpdated)
|
||||
{
|
||||
UpdateItemInLibraryCache(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the item in library cache.
|
||||
/// </summary>
|
||||
@@ -1069,13 +1046,61 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
return comparer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task CreateItem(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
await SaveItem(item, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
UpdateItemInLibraryCache(item);
|
||||
|
||||
if (ItemAdded != null)
|
||||
{
|
||||
ItemAdded(this, new ItemChangeEventArgs { Item = item });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task UpdateItem(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
await SaveItem(item, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
UpdateItemInLibraryCache(item);
|
||||
|
||||
if (ItemUpdated != null)
|
||||
{
|
||||
ItemUpdated(this, new ItemChangeEventArgs { Item = item });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the item removed.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
public void ReportItemRemoved(BaseItem item)
|
||||
{
|
||||
if (ItemRemoved != null)
|
||||
{
|
||||
ItemRemoved(this, new ItemChangeEventArgs { Item = item });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public Task SaveItem(BaseItem item, CancellationToken cancellationToken)
|
||||
private Task SaveItem(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
return ItemRepository.SaveItem(item, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -43,21 +43,21 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
//BaseItem.LibraryManager.LibraryChanged += LibraryChanged;
|
||||
}
|
||||
|
||||
public void LibraryChanged(object source, ChildrenChangedEventArgs changeInformation)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (changeInformation.ItemsAdded.Count + changeInformation.ItemsUpdated.Count > 0)
|
||||
{
|
||||
LuceneSearch.AddUpdateLuceneIndex(changeInformation.ItemsAdded.Concat(changeInformation.ItemsUpdated));
|
||||
}
|
||||
//public void LibraryChanged(object source, ChildrenChangedEventArgs changeInformation)
|
||||
//{
|
||||
// Task.Run(() =>
|
||||
// {
|
||||
// if (changeInformation.ItemsAdded.Count + changeInformation.ItemsUpdated.Count > 0)
|
||||
// {
|
||||
// LuceneSearch.AddUpdateLuceneIndex(changeInformation.ItemsAdded.Concat(changeInformation.ItemsUpdated));
|
||||
// }
|
||||
|
||||
if (changeInformation.ItemsRemoved.Count > 0)
|
||||
{
|
||||
LuceneSearch.RemoveFromLuceneIndex(changeInformation.ItemsRemoved);
|
||||
}
|
||||
});
|
||||
}
|
||||
// if (changeInformation.ItemsRemoved.Count > 0)
|
||||
// {
|
||||
// LuceneSearch.RemoveFromLuceneIndex(changeInformation.ItemsRemoved);
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
|
||||
public void AddItemsToIndex(IEnumerable<BaseItem> items)
|
||||
{
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
// Image is already in the cache
|
||||
item.PrimaryImagePath = path;
|
||||
|
||||
await _libraryManager.SaveItem(item, cancellationToken).ConfigureAwait(false);
|
||||
await _libraryManager.UpdateItem(item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
// Image is already in the cache
|
||||
item.PrimaryImagePath = path;
|
||||
|
||||
await _libraryManager.SaveItem(item, cancellationToken).ConfigureAwait(false);
|
||||
await _libraryManager.UpdateItem(item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user