aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data/SqliteItemRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Data/SqliteItemRepository.cs')
-rw-r--r--Emby.Server.Implementations/Data/SqliteItemRepository.cs120
1 files changed, 56 insertions, 64 deletions
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index 8c16216b9..c158f2e51 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -372,7 +372,7 @@ namespace Emby.Server.Implementations.Data
userDataRepo.Initialize(WriteLock, _connection);
- _shrinkMemoryTimer = _timerFactory.Create(OnShrinkMemoryTimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(15));
+ _shrinkMemoryTimer = _timerFactory.Create(OnShrinkMemoryTimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(30));
}
private void OnShrinkMemoryTimerCallback(object state)
@@ -2384,8 +2384,17 @@ namespace Emby.Server.Implementations.Data
var excludeIds = query.ExcludeItemIds.ToList();
excludeIds.Add(item.Id.ToString("N"));
- query.ExcludeItemIds = excludeIds.ToArray();
+ if (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains(typeof(Trailer).Name))
+ {
+ var hasTrailers = item as IHasTrailers;
+ if (hasTrailers != null)
+ {
+ excludeIds.AddRange(hasTrailers.GetTrailerIds().Select(i => i.ToString("N")));
+ }
+ }
+
+ query.ExcludeItemIds = excludeIds.ToArray();
query.ExcludeProviderIds = item.ProviderIds;
}
@@ -2548,57 +2557,53 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- return connection.RunInTransaction(db =>
- {
- var list = new List<BaseItem>();
+ var list = new List<BaseItem>();
- using (var statement = PrepareStatementSafe(db, commandText))
+ using (var statement = PrepareStatementSafe(connection, commandText))
+ {
+ if (EnableJoinUserData(query))
{
- if (EnableJoinUserData(query))
- {
- statement.TryBind("@UserId", query.User.Id);
- }
+ statement.TryBind("@UserId", query.User.Id);
+ }
- BindSimilarParams(query, statement);
+ BindSimilarParams(query, statement);
- // Running this again will bind the params
- GetWhereClauses(query, statement);
+ // Running this again will bind the params
+ GetWhereClauses(query, statement);
- foreach (var row in statement.ExecuteQuery())
+ foreach (var row in statement.ExecuteQuery())
+ {
+ var item = GetItem(row, query);
+ if (item != null)
{
- var item = GetItem(row, query);
- if (item != null)
- {
- list.Add(item);
- }
+ list.Add(item);
}
}
+ }
- // Hack for right now since we currently don't support filtering out these duplicates within a query
- if (query.EnableGroupByMetadataKey)
+ // 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)
{
- var limit = query.Limit ?? int.MaxValue;
- limit -= 4;
- var newList = new List<BaseItem>();
+ AddItem(newList, item);
- foreach (var item in list)
+ if (newList.Count >= limit)
{
- AddItem(newList, item);
-
- if (newList.Count >= limit)
- {
- break;
- }
+ break;
}
-
- list = newList;
}
- LogQueryTime("GetItemList", commandText, now);
+ list = newList;
+ }
- return list;
+ LogQueryTime("GetItemList", commandText, now);
- }, ReadTransactionMode);
+ return list;
}
}
}
@@ -2652,7 +2657,7 @@ namespace Emby.Server.Implementations.Data
{
//Logger.Debug("{2} query time: {0}ms. Query: {1}",
// Convert.ToInt32(elapsed),
- // cmd.CommandText,
+ // commandText,
// methodName);
}
}
@@ -2825,8 +2830,9 @@ namespace Emby.Server.Implementations.Data
{
if (orderBy.Count == 0)
{
- orderBy.Add(new Tuple<string, SortOrder>("SimilarityScore", SortOrder.Descending));
orderBy.Add(new Tuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending));
+ orderBy.Add(new Tuple<string, SortOrder>("SimilarityScore", SortOrder.Descending));
+ //orderBy.Add(new Tuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending));
query.SortOrder = SortOrder.Descending;
enableOrderInversion = false;
}
@@ -3212,6 +3218,11 @@ namespace Emby.Server.Implementations.Data
private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statement, string paramSuffix = "")
{
+ if (query.IsResumable ?? false)
+ {
+ query.IsVirtualItem = false;
+ }
+
var whereClauses = new List<string>();
if (EnableJoinUserData(query))
@@ -3372,9 +3383,9 @@ namespace Emby.Server.Implementations.Data
}
}
- if (query.SimilarTo != null)
+ if (query.SimilarTo != null && query.MinSimilarityScore > 0)
{
- whereClauses.Add("SimilarityScore > 0");
+ whereClauses.Add("SimilarityScore > " + (query.MinSimilarityScore - 1).ToString(CultureInfo.InvariantCulture));
}
if (query.IsFolder.HasValue)
@@ -3616,10 +3627,12 @@ namespace Emby.Server.Implementations.Data
var index = 0;
foreach (var type in query.TrailerTypes)
{
- clauses.Add("TrailerTypes like @TrailerTypes" + index);
+ var paramName = "@TrailerTypes" + index;
+
+ clauses.Add("TrailerTypes like " + paramName);
if (statement != null)
{
- statement.TryBind("@TrailerTypes" + index, "%" + type + "%");
+ statement.TryBind(paramName, "%" + type + "%");
}
index++;
}
@@ -4085,27 +4098,6 @@ namespace Emby.Server.Implementations.Data
whereClauses.Add("LocationType in (" + val + ")");
}
- if (query.ExcludeLocationTypes.Length == 1)
- {
- if (query.ExcludeLocationTypes[0] == LocationType.Virtual && _config.Configuration.SchemaVersion >= 90)
- {
- query.IsVirtualItem = false;
- }
- else
- {
- whereClauses.Add("LocationType<>@ExcludeLocationTypes");
- if (statement != null)
- {
- statement.TryBind("@ExcludeLocationTypes", query.ExcludeLocationTypes[0].ToString());
- }
- }
- }
- else if (query.ExcludeLocationTypes.Length > 1)
- {
- var val = string.Join(",", query.ExcludeLocationTypes.Select(i => "'" + i + "'").ToArray());
-
- whereClauses.Add("LocationType not in (" + val + ")");
- }
if (query.IsVirtualItem.HasValue)
{
whereClauses.Add("IsVirtualItem=@IsVirtualItem");
@@ -4221,7 +4213,7 @@ namespace Emby.Server.Implementations.Data
var paramName = "@ExcludeProviderId" + index;
//excludeIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = '" + pair.Key + "'), '') <> " + paramName + ")");
- excludeIds.Add("ProviderIds not like " + paramName);
+ excludeIds.Add("(ProviderIds is null or ProviderIds not like " + paramName + ")");
if (statement != null)
{
statement.TryBind(paramName, "%" + pair.Key + "=" + pair.Value + "%");