Fixed a file system issue and also added a few more performance tweaks

pull/702/head
LukePulverenti Luke Pulverenti luke pulverenti 12 years ago
parent 906ad3cb1a
commit e6a95defc9

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Events
{
@ -15,15 +15,17 @@ namespace MediaBrowser.Controller.Events
public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntry(string path, bool? isFolder)
{
foreach (KeyValuePair<string, WIN32_FIND_DATA> entry in FileSystemChildren)
for (int i = 0; i < FileSystemChildren.Length; i++)
{
KeyValuePair<string, WIN32_FIND_DATA> entry = FileSystemChildren[i];
if (isFolder.HasValue)
{
if (isFolder.Value && entry.Value.IsDirectory)
if (isFolder.Value && !entry.Value.IsDirectory)
{
continue;
}
else if (!isFolder.Value && !entry.Value.IsDirectory)
else if (!isFolder.Value && entry.Value.IsDirectory)
{
continue;
}
@ -40,15 +42,17 @@ namespace MediaBrowser.Controller.Events
public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntryByName(string name, bool? isFolder)
{
foreach (KeyValuePair<string, WIN32_FIND_DATA> entry in FileSystemChildren)
for (int i = 0; i < FileSystemChildren.Length; i++)
{
KeyValuePair<string, WIN32_FIND_DATA> entry = FileSystemChildren[i];
if (isFolder.HasValue)
{
if (isFolder.Value && entry.Value.IsDirectory)
if (isFolder.Value && !entry.Value.IsDirectory)
{
continue;
}
else if (!isFolder.Value && !entry.Value.IsDirectory)
else if (!isFolder.Value && entry.Value.IsDirectory)
{
continue;
}

@ -2,11 +2,9 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.Events;
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.IO;
namespace MediaBrowser.Controller.Providers
{
@ -48,8 +46,10 @@ namespace MediaBrowser.Controller.Providers
/// </summary>
private void PopulateImages(BaseEntity item, ItemResolveEventArgs args)
{
foreach (KeyValuePair<string, WIN32_FIND_DATA> file in args.FileSystemChildren)
for (int i = 0; i < args.FileSystemChildren.Length; i++)
{
var file = args.FileSystemChildren[i];
if (file.Value.IsDirectory)
{
continue;
@ -81,8 +81,10 @@ namespace MediaBrowser.Controller.Providers
{
List<string> backdropFiles = new List<string>();
foreach (KeyValuePair<string, WIN32_FIND_DATA> file in args.FileSystemChildren)
for (int i = 0; i < args.FileSystemChildren.Length; i++)
{
var file = args.FileSystemChildren[i];
if (file.Value.IsDirectory)
{
continue;
@ -126,7 +128,7 @@ namespace MediaBrowser.Controller.Providers
}
}
if (backdropFiles.Any())
if (backdropFiles.Count > 0)
{
item.BackdropImagePaths = backdropFiles;
}

@ -32,8 +32,10 @@ namespace MediaBrowser.Controller.Providers
List<Video> localTrailers = new List<Video>();
foreach (string file in allFiles)
for (int i = 0; i < allFiles.Length; i++)
{
string file = allFiles[i];
BaseItem child = await Kernel.Instance.ItemController.GetItem(file).ConfigureAwait(false);
Video video = child as Video;

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition;
using System.IO;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Resolvers
@ -51,8 +49,10 @@ namespace MediaBrowser.Controller.Resolvers
}
// Also check the subfolders for bluray or dvd
foreach (KeyValuePair<string, WIN32_FIND_DATA> folder in args.FileSystemChildren)
for (int i = 0; i < args.FileSystemChildren.Length; i++)
{
var folder = args.FileSystemChildren[i];
if (!folder.Value.IsDirectory)
{
continue;

@ -19,12 +19,6 @@ namespace MediaBrowser.Movies.Resolvers
{
if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("Movies", StringComparison.OrdinalIgnoreCase))
{
// Optimization to avoid running these tests against VF's
if (args.Parent != null && args.Parent.IsRoot)
{
return null;
}
var metadataFile = args.GetFileSystemEntryByName("movie.xml", false);
if (metadataFile.HasValue || Path.GetFileName(args.Path).IndexOf("[tmdbid=", StringComparison.OrdinalIgnoreCase) != -1)
@ -53,8 +47,10 @@ namespace MediaBrowser.Movies.Resolvers
private Movie GetMovie(ItemResolveEventArgs args)
{
foreach (var child in args.FileSystemChildren)
for (var i = 0; i < args.FileSystemChildren.Length; i++)
{
var child = args.FileSystemChildren[i];
ItemResolveEventArgs childArgs = new ItemResolveEventArgs()
{
Path = child.Key,

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using System;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.TV.Entities
@ -9,6 +8,22 @@ namespace MediaBrowser.TV.Entities
/// <summary>
/// Store these to reduce disk access in Episode Resolver
/// </summary>
internal IEnumerable<string> MetadataFiles { get; set; }
internal string[] MetadataFiles { get; set; }
/// <summary>
/// Determines if the metafolder contains a given file
/// </summary>
internal bool ContainsMetadataFile(string file)
{
for (int i = 0; i < MetadataFiles.Length; i++)
{
if (MetadataFiles[i].Equals(file, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
}
}

@ -53,7 +53,7 @@ namespace MediaBrowser.TV.Providers
}
else
{
item.PrimaryImagePath = imageFiles.FirstOrDefault(f => season.MetadataFiles.Any(s => s.Equals(f, StringComparison.OrdinalIgnoreCase)));
item.PrimaryImagePath = imageFiles.FirstOrDefault(f => season.ContainsMetadataFile(f));
}
}
}

@ -1,7 +1,5 @@
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Providers;
@ -26,18 +24,22 @@ namespace MediaBrowser.TV.Providers
public async override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
{
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
await Task.Run(() =>
{
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
Episode episode = item as Episode;
Episode episode = item as Episode;
string episodeFileName = Path.GetFileName(episode.Path);
string episodeFileName = Path.GetFileName(episode.Path);
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".xml"));
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".xml"));
FetchMetadata(episode, args.Parent as Season, metadataFile);
await FetchMetadata(episode, args.Parent as Season, metadataFile).ConfigureAwait(false);
}).ConfigureAwait(false);
}
private async Task FetchMetadata(Episode item, Season season, string metadataFile)
private void FetchMetadata(Episode item, Season season, string metadataFile)
{
if (season == null)
{
@ -50,13 +52,13 @@ namespace MediaBrowser.TV.Providers
}
else
{
if (!season.MetadataFiles.Any(s => s.Equals(metadataFile, StringComparison.OrdinalIgnoreCase)))
if (!season.ContainsMetadataFile(metadataFile))
{
return;
}
}
await Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); }).ConfigureAwait(false);
new EpisodeXmlParser().Fetch(item, metadataFile);
}
}
}

@ -3,7 +3,6 @@ using System.IO;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.TV.Entities;
using MediaBrowser.TV.Metadata;
namespace MediaBrowser.TV.Resolvers
{

@ -14,12 +14,6 @@ namespace MediaBrowser.TV.Resolvers
{
if (args.IsFolder && (args.VirtualFolderCollectionType ?? string.Empty).Equals("TV", StringComparison.OrdinalIgnoreCase))
{
// Optimization to avoid running these tests against VF's
if (args.Parent != null && args.Parent.IsRoot)
{
return null;
}
// Optimization to avoid running these tests against Seasons
if (args.Parent is Series)
{

@ -53,10 +53,12 @@ namespace MediaBrowser.TV
return seasonPathExpressions.Any(r => r.IsMatch(path));
}
public static bool IsSeriesFolder(string path, IEnumerable<KeyValuePair<string, WIN32_FIND_DATA>> fileSystemChildren)
public static bool IsSeriesFolder(string path, KeyValuePair<string, WIN32_FIND_DATA>[] fileSystemChildren)
{
foreach (var child in fileSystemChildren)
for (int i = 0; i < fileSystemChildren.Length; i++)
{
var child = fileSystemChildren[i];
if (child.Value.IsDirectory)
{
if (IsSeasonFolder(child.Key))
@ -76,22 +78,6 @@ namespace MediaBrowser.TV
return false;
}
public static bool IsEpisode(string fullPath)
{
bool isInSeason = IsSeasonFolder(Path.GetDirectoryName(fullPath));
if (isInSeason)
{
return true;
}
else if (EpisodeNumberFromFile(fullPath, isInSeason) != null)
{
return true;
}
return false;
}
public static string EpisodeNumberFromFile(string fullPath, bool isInSeason)
{
string fl = fullPath.ToLower();

Loading…
Cancel
Save