diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-12-12 14:40:27 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-12-12 14:40:27 -0500 |
| commit | d84bb7160f8c3cfc953cdece890264d70e504e39 (patch) | |
| tree | fd325dc95a3dfb6acf817c035d15870530b0bc48 /Emby.Server.Implementations/Data | |
| parent | c2d0fd99852aae31379b89591b538d075743362f (diff) | |
update next up queries
Diffstat (limited to 'Emby.Server.Implementations/Data')
| -rw-r--r-- | Emby.Server.Implementations/Data/SqliteItemRepository.cs | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 1f0f5a521..14b81022d 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -2443,6 +2443,66 @@ namespace Emby.Server.Implementations.Data return " from TypedBaseItems " + alias; } + public int GetCount(InternalItemsQuery query) + { + if (query == null) + { + throw new ArgumentNullException("query"); + } + + CheckDisposed(); + + //Logger.Info("GetItemList: " + _environmentInfo.StackTrace); + + var now = DateTime.UtcNow; + + // 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; + } + + var commandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, new [] { "count(distinct PresentationUniqueKey)" })) + GetFromText(); + commandText += GetJoinUserDataText(query); + + var whereClauses = GetWhereClauses(query, null); + + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + commandText += whereText; + + //commandText += GetGroupBy(query); + + int count = 0; + + using (WriteLock.Read()) + { + using (var connection = CreateConnection(true)) + { + using (var statement = PrepareStatementSafe(connection, commandText)) + { + if (EnableJoinUserData(query)) + { + statement.TryBind("@UserId", query.User.Id); + } + + BindSimilarParams(query, statement); + + // Running this again will bind the params + GetWhereClauses(query, statement); + + count = statement.ExecuteQuery().SelectScalarInt().First(); + } + } + + LogQueryTime("GetCount", commandText, now); + } + + return count; + } + public List<BaseItem> GetItemList(InternalItemsQuery query) { if (query == null) @@ -2859,7 +2919,7 @@ namespace Emby.Server.Implementations.Data } if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase)) { - return new Tuple<string, bool>("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)", false); + return new Tuple<string, bool>("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)", false); } return new Tuple<string, bool>(name, false); |
