fix duplicates in suggestions

pull/702/head
Luke Pulverenti 9 years ago
parent 02b0734029
commit db1130166f

@ -156,7 +156,9 @@ namespace MediaBrowser.Api.Movies
typeof(LiveTvProgram).Name
},
IsMovie = true,
SimilarTo = item
SimilarTo = item,
EnableGroupByMetadataKey = true
}).ToList();
var dtoOptions = GetDtoOptions(request);
@ -205,7 +207,8 @@ namespace MediaBrowser.Api.Movies
SortOrder = SortOrder.Descending,
Limit = 10,
IsFavoriteOrLiked = true,
ExcludeItemIds = recentlyPlayedMovies.Select(i => i.Id.ToString("N")).ToArray()
ExcludeItemIds = recentlyPlayedMovies.Select(i => i.Id.ToString("N")).ToArray(),
EnableGroupByMetadataKey = true
}, parentIds).ToList();
@ -283,7 +286,8 @@ namespace MediaBrowser.Api.Movies
typeof(Trailer).Name,
typeof(LiveTvProgram).Name
},
IsMovie = true
IsMovie = true,
EnableGroupByMetadataKey = true
}).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
.Take(itemLimit)
@ -317,7 +321,8 @@ namespace MediaBrowser.Api.Movies
typeof(Trailer).Name,
typeof(LiveTvProgram).Name
},
IsMovie = true
IsMovie = true,
EnableGroupByMetadataKey = true
}).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
.Take(itemLimit)
@ -350,7 +355,8 @@ namespace MediaBrowser.Api.Movies
typeof(LiveTvProgram).Name
},
IsMovie = true,
SimilarTo = item
SimilarTo = item,
EnableGroupByMetadataKey = true
}).ToList();

@ -143,7 +143,7 @@ namespace MediaBrowser.Controller.Entities
public bool EnableTotalRecordCount { get; set; }
public bool ForceDirect { get; set; }
public Dictionary<string, string> ExcludeProviderIds { get; set; }
public string GroupByAncestorOfType { get; set; }
public bool EnableGroupByMetadataKey { get; set; }
public InternalItemsQuery()
{

@ -1622,7 +1622,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
return false;
}
if (query.SimilarTo != null)
if (query.SimilarTo != null && query.User != null)
{
return true;
}
@ -1757,11 +1757,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
var groups = new List<string>();
if (!string.IsNullOrWhiteSpace(query.GroupByAncestorOfType))
{
groups.Add("(Select PresentationUniqueKey from TypedBaseItems B where B.Type = 'MediaBrowser.Controller.Entities.TV.Series' And B.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))");
}
if (EnableGroupByPresentationUniqueKey(query))
{
groups.Add("PresentationUniqueKey");
@ -1793,6 +1788,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
var list = new List<BaseItem>();
// Hack for right now since we currently don't support filtering out these duplicates within a query
if (query.Limit.HasValue && query.EnableGroupByMetadataKey)
{
query.Limit = query.Limit.Value + 4;
}
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, _retriveItemColumns, cmd)) + GetFromText();
@ -1845,9 +1846,57 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
// Hack for right now since we currently don't support filtering out these duplicates within a query
if (query.EnableGroupByMetadataKey)
{
var limit = query.Limit ?? int.MaxValue;
limit -= 4;
var newList = new List<BaseItem>();
foreach (var item in list)
{
AddItem(newList, item);
if (newList.Count >= limit)
{
break;
}
}
list = newList;
}
return list;
}
private void AddItem(List<BaseItem> items, BaseItem newItem)
{
var providerIds = newItem.ProviderIds.ToList();
for (var i = 0; i < items.Count; i++)
{
var item = items[i];
foreach (var providerId in providerIds)
{
if (providerId.Key == MetadataProviders.TmdbCollection.ToString())
{
continue;
}
if (item.GetProviderId(providerId.Key) == providerId.Value)
{
if (newItem.SourceType == SourceType.Library)
{
items[i] = newItem;
}
return;
}
}
}
items.Add(newItem);
}
private void LogQueryTime(string methodName, IDbCommand cmd, DateTime startDate)
{
var elapsed = (DateTime.UtcNow - startDate).TotalMilliseconds;
@ -3869,7 +3918,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
return counts;
}
var allTypes = typeString.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries)
var allTypes = typeString.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
.ToLookup(i => i).ToList();
foreach (var type in allTypes)

@ -276,11 +276,6 @@ namespace MediaBrowser.Server.Mono.Native
{
"https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-git-20160215-64bit-static.7z"
};
case Architecture.X86:
return new[]
{
"https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-git-20160215-32bit-static.7z"
};
}
break;
}

Loading…
Cancel
Save