aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/BaseApiService.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-05-06 00:50:39 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-05-06 00:50:39 -0400
commit5a496a1fc8d9ee2e728d6f712ae6bdf4862183f1 (patch)
tree70f8d08ae6cd74e08f5800136fe73728fd0ad3d0 /MediaBrowser.Api/BaseApiService.cs
parent242fb3c770a657e3c2a23ac21ec7d902879d8023 (diff)
reduce recursive querying
Diffstat (limited to 'MediaBrowser.Api/BaseApiService.cs')
-rw-r--r--MediaBrowser.Api/BaseApiService.cs189
1 files changed, 78 insertions, 111 deletions
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs
index 30750b374..44d459a01 100644
--- a/MediaBrowser.Api/BaseApiService.cs
+++ b/MediaBrowser.Api/BaseApiService.cs
@@ -79,7 +79,7 @@ namespace MediaBrowser.Api
}
}
}
-
+
/// <summary>
/// To the optimized serialized result using cache.
/// </summary>
@@ -118,9 +118,6 @@ namespace MediaBrowser.Api
return ResultFactory.GetStaticFileResult(Request, path);
}
- private readonly char[] _dashReplaceChars = { '?', '/', '&' };
- private const char SlugChar = '-';
-
protected DtoOptions GetDtoOptions(object request)
{
var options = new DtoOptions();
@@ -154,152 +151,122 @@ namespace MediaBrowser.Api
protected MusicArtist GetArtist(string name, ILibraryManager libraryManager)
{
- return libraryManager.GetArtist(DeSlugArtistName(name, libraryManager));
- }
-
- protected Studio GetStudio(string name, ILibraryManager libraryManager)
- {
- return libraryManager.GetStudio(DeSlugStudioName(name, libraryManager));
- }
-
- protected Genre GetGenre(string name, ILibraryManager libraryManager)
- {
- return libraryManager.GetGenre(DeSlugGenreName(name, libraryManager));
- }
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
+ {
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(MusicArtist).Name }
- protected MusicGenre GetMusicGenre(string name, ILibraryManager libraryManager)
- {
- return libraryManager.GetMusicGenre(DeSlugGenreName(name, libraryManager));
- }
+ }).OfType<MusicArtist>().FirstOrDefault();
- protected GameGenre GetGameGenre(string name, ILibraryManager libraryManager)
- {
- return libraryManager.GetGameGenre(DeSlugGameGenreName(name, libraryManager));
- }
+ if (result != null)
+ {
+ return result;
+ }
+ }
- protected Person GetPerson(string name, ILibraryManager libraryManager)
- {
- return libraryManager.GetPerson(DeSlugPersonName(name, libraryManager));
+ return libraryManager.GetArtist(name);
}
- /// <summary>
- /// Deslugs an artist name by finding the correct entry in the library
- /// </summary>
- /// <param name="name"></param>
- /// <param name="libraryManager"></param>
- /// <returns></returns>
- protected string DeSlugArtistName(string name, ILibraryManager libraryManager)
+ protected Studio GetStudio(string name, ILibraryManager libraryManager)
{
- if (name.IndexOf(SlugChar) == -1)
- {
- return name;
- }
-
- var items = libraryManager.GetItemList(new InternalItemsQuery
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
{
- IncludeItemTypes = new[] { typeof(Audio).Name, typeof(MusicVideo).Name, typeof(MusicAlbum).Name }
- });
-
- return items
- .OfType<IHasArtist>()
- .SelectMany(i => i.AllArtists)
- .DistinctNames()
- .FirstOrDefault(i =>
+ var result = libraryManager.GetItemList(new InternalItemsQuery
{
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(Studio).Name }
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
+ }).OfType<Studio>().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
- }) ?? name;
+ return libraryManager.GetStudio(name);
}
- /// <summary>
- /// Deslugs a genre name by finding the correct entry in the library
- /// </summary>
- protected string DeSlugGenreName(string name, ILibraryManager libraryManager)
+ protected Genre GetGenre(string name, ILibraryManager libraryManager)
{
- if (name.IndexOf(SlugChar) == -1)
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
{
- return name;
- }
-
- return libraryManager.RootFolder.GetRecursiveChildren()
- .SelectMany(i => i.Genres)
- .DistinctNames()
- .FirstOrDefault(i =>
+ var result = libraryManager.GetItemList(new InternalItemsQuery
{
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(Genre).Name }
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
+ }).OfType<Genre>().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
- }) ?? name;
+ return libraryManager.GetGenre(name);
}
- protected string DeSlugGameGenreName(string name, ILibraryManager libraryManager)
+ protected MusicGenre GetMusicGenre(string name, ILibraryManager libraryManager)
{
- if (name.IndexOf(SlugChar) == -1)
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
{
- return name;
- }
+ var result = libraryManager.GetItemList(new InternalItemsQuery
+ {
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(MusicGenre).Name }
- var items = libraryManager.GetItemList(new InternalItemsQuery
- {
- IncludeItemTypes = new[] { typeof(Game).Name }
- });
+ }).OfType<MusicGenre>().FirstOrDefault();
- return items
- .SelectMany(i => i.Genres)
- .DistinctNames()
- .FirstOrDefault(i =>
+ if (result != null)
{
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
-
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
+ return result;
+ }
+ }
- }) ?? name;
+ return libraryManager.GetMusicGenre(name);
}
- /// <summary>
- /// Deslugs a studio name by finding the correct entry in the library
- /// </summary>
- protected string DeSlugStudioName(string name, ILibraryManager libraryManager)
+ protected GameGenre GetGameGenre(string name, ILibraryManager libraryManager)
{
- if (name.IndexOf(SlugChar) == -1)
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
{
- return name;
- }
-
- return libraryManager.RootFolder
- .GetRecursiveChildren()
- .SelectMany(i => i.Studios)
- .DistinctNames()
- .FirstOrDefault(i =>
+ var result = libraryManager.GetItemList(new InternalItemsQuery
{
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(GameGenre).Name }
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
+ }).OfType<GameGenre>().FirstOrDefault();
- }) ?? name;
+ if (result != null)
+ {
+ return result;
+ }
+ }
+
+ return libraryManager.GetGameGenre(name);
}
- /// <summary>
- /// Deslugs a person name by finding the correct entry in the library
- /// </summary>
- protected string DeSlugPersonName(string name, ILibraryManager libraryManager)
+ protected Person GetPerson(string name, ILibraryManager libraryManager)
{
- if (name.IndexOf(SlugChar) == -1)
+ if (name.IndexOf(BaseItem.SlugChar) != -1)
{
- return name;
- }
-
- return libraryManager.GetPeopleNames(new InternalPeopleQuery())
- .FirstOrDefault(i =>
+ var result = libraryManager.GetItemList(new InternalItemsQuery
{
- i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar));
+ SlugName = name,
+ IncludeItemTypes = new[] { typeof(Person).Name }
- return string.Equals(i, name, StringComparison.OrdinalIgnoreCase);
+ }).OfType<Person>().FirstOrDefault();
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
- }) ?? name;
+ return libraryManager.GetPerson(name);
}
protected string GetPathValue(int index)