reduce scans when changing library

This commit is contained in:
Luke Pulverenti 2013-08-13 10:41:45 -04:00
parent e3fd8525d6
commit 242f0f21dc
2 changed files with 93 additions and 43 deletions

View File

@ -1,11 +1,12 @@
using System.Threading;
using MediaBrowser.Controller;
using MediaBrowser.Controller;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using ServiceStack.ServiceHost;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace MediaBrowser.Api.Library
{
@ -152,6 +153,8 @@ namespace MediaBrowser.Api.Library
/// </summary>
private readonly ILibraryManager _libraryManager;
private readonly IDirectoryWatchers _directoryWatchers;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryStructureService"/> class.
/// </summary>
@ -159,7 +162,7 @@ namespace MediaBrowser.Api.Library
/// <param name="userManager">The user manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <exception cref="System.ArgumentNullException">appPaths</exception>
public LibraryStructureService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager)
public LibraryStructureService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IDirectoryWatchers directoryWatchers)
{
if (appPaths == null)
{
@ -169,6 +172,7 @@ namespace MediaBrowser.Api.Library
_userManager = userManager;
_appPaths = appPaths;
_libraryManager = libraryManager;
_directoryWatchers = directoryWatchers;
}
/// <summary>
@ -199,6 +203,10 @@ namespace MediaBrowser.Api.Library
/// </summary>
/// <param name="request">The request.</param>
public void Post(AddVirtualFolder request)
{
_directoryWatchers.Stop();
try
{
if (string.IsNullOrEmpty(request.UserId))
{
@ -210,6 +218,11 @@ namespace MediaBrowser.Api.Library
LibraryHelpers.AddVirtualFolder(request.Name, request.CollectionType, user, _appPaths);
}
}
finally
{
_directoryWatchers.Start();
}
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}
@ -219,6 +232,10 @@ namespace MediaBrowser.Api.Library
/// </summary>
/// <param name="request">The request.</param>
public void Post(RenameVirtualFolder request)
{
_directoryWatchers.Stop();
try
{
if (string.IsNullOrEmpty(request.UserId))
{
@ -230,6 +247,11 @@ namespace MediaBrowser.Api.Library
LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, user, _appPaths);
}
}
finally
{
_directoryWatchers.Start();
}
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}
@ -239,6 +261,10 @@ namespace MediaBrowser.Api.Library
/// </summary>
/// <param name="request">The request.</param>
public void Delete(RemoveVirtualFolder request)
{
_directoryWatchers.Stop();
try
{
if (string.IsNullOrEmpty(request.UserId))
{
@ -250,6 +276,11 @@ namespace MediaBrowser.Api.Library
LibraryHelpers.RemoveVirtualFolder(request.Name, user, _appPaths);
}
}
finally
{
_directoryWatchers.Start();
}
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}
@ -259,6 +290,10 @@ namespace MediaBrowser.Api.Library
/// </summary>
/// <param name="request">The request.</param>
public void Post(AddMediaPath request)
{
_directoryWatchers.Stop();
try
{
if (string.IsNullOrEmpty(request.UserId))
{
@ -270,6 +305,11 @@ namespace MediaBrowser.Api.Library
LibraryHelpers.AddMediaPath(request.Name, request.Path, user, _appPaths);
}
}
finally
{
_directoryWatchers.Start();
}
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}
@ -279,6 +319,10 @@ namespace MediaBrowser.Api.Library
/// </summary>
/// <param name="request">The request.</param>
public void Delete(RemoveMediaPath request)
{
_directoryWatchers.Stop();
try
{
if (string.IsNullOrEmpty(request.UserId))
{
@ -290,6 +334,11 @@ namespace MediaBrowser.Api.Library
LibraryHelpers.RemoveMediaPath(request.Name, request.Path, user, _appPaths);
}
}
finally
{
_directoryWatchers.Start();
}
_libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None);
}

View File

@ -576,6 +576,7 @@ namespace MediaBrowser.Server.Implementations.IO
}
}
_fileSystemWatchers.Clear();
_affectedPaths.Clear();
}