aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
diff options
context:
space:
mode:
authorEric Reed <ebr@mediabrowser3.com>2013-03-15 15:08:49 -0400
committerEric Reed <ebr@mediabrowser3.com>2013-03-15 15:08:49 -0400
commitc02ac2a8ca0a01e6951d5ccca13e98a118057505 (patch)
tree4e1215674203c4f9eaa95671727d72a4492f62b0 /MediaBrowser.Server.Implementations/Library/LibraryManager.cs
parentb86a03bbdcca3c03b2cd880e607472bc7b3d0850 (diff)
Manage some items as single instance throughout #54
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs40
1 files changed, 36 insertions, 4 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index 549ea9be2..71fe6e125 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -106,6 +106,13 @@ namespace MediaBrowser.Server.Implementations.Library
private IServerConfigurationManager ConfigurationManager { get; set; }
/// <summary>
+ /// A collection of items that may be referenced from multiple physical places in the library
+ /// (typically, multiple user roots). We store them here and be sure they all reference a
+ /// single instance.
+ /// </summary>
+ private ConcurrentDictionary<Guid, BaseItem> ByReferenceItems { get; set; }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="LibraryManager" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
@@ -120,6 +127,7 @@ namespace MediaBrowser.Server.Implementations.Library
_taskManager = taskManager;
_userManager = userManager;
ConfigurationManager = configurationManager;
+ ByReferenceItems = new ConcurrentDictionary<Guid, BaseItem>();
ConfigurationManager.ConfigurationUpdated += kernel_ConfigurationUpdated;
@@ -232,11 +240,35 @@ namespace MediaBrowser.Server.Implementations.Library
if (item != null)
{
ResolverHelper.SetInitialItemValues(item, args);
+
+ // Now handle the issue with posibly having the same item referenced from multiple physical
+ // places within the library. Be sure we always end up with just one instance.
+ if (item is IByReferenceItem)
+ {
+ item = GetOrAddByReferenceItem(item);
+ }
}
return item;
}
+
+ /// <summary>
+ /// Ensure supplied item has only one instance throughout
+ /// </summary>
+ /// <param name="item"></param>
+ /// <returns>The proper instance to the item</returns>
+ public BaseItem GetOrAddByReferenceItem(BaseItem item)
+ {
+ // Add this item to our list if not there already
+ if (!ByReferenceItems.TryAdd(item.Id, item))
+ {
+ // Already there - return the existing reference
+ item = ByReferenceItems[item.Id];
+ }
+ return item;
+ }
+
/// <summary>
/// Resolves a path into a BaseItem
/// </summary>
@@ -617,10 +649,10 @@ namespace MediaBrowser.Server.Implementations.Library
// Now validate the entire media library
await RootFolder.ValidateChildren(progress, cancellationToken, recursive: true).ConfigureAwait(false);
- foreach (var user in _userManager.Users)
- {
- await user.ValidateMediaLibrary(new Progress<double> { }, cancellationToken).ConfigureAwait(false);
- }
+ //foreach (var user in _userManager.Users)
+ //{
+ // await user.ValidateMediaLibrary(new Progress<double> { }, cancellationToken).ConfigureAwait(false);
+ //}
}
/// <summary>