aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/Activity/ActivityRepository.cs44
-rw-r--r--Emby.Server.Implementations/Data/BaseSqliteRepository.cs2
-rw-r--r--Emby.Server.Implementations/Data/SqliteItemRepository.cs306
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserDataRepository.cs24
-rw-r--r--Emby.Server.Implementations/Emby.Server.Implementations.csproj1
-rw-r--r--Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs6
-rw-r--r--Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs77
-rw-r--r--Emby.Server.Implementations/Library/UserDataManager.cs2
-rw-r--r--Emby.Server.Implementations/Security/AuthenticationRepository.cs44
-rw-r--r--Emby.Server.Implementations/TV/TVSeriesManager.cs70
10 files changed, 365 insertions, 211 deletions
diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs
index 17aef7268..fda8b949b 100644
--- a/Emby.Server.Implementations/Activity/ActivityRepository.cs
+++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs
@@ -84,6 +84,9 @@ namespace Emby.Server.Implementations.Activity
{
using (var connection = CreateConnection(true))
{
+ var list = new List<ActivityLogEntry>();
+ int totalRecordCount = 0;
+
var commandText = BaseActivitySelectText;
var whereClauses = new List<string>();
@@ -120,32 +123,37 @@ namespace Emby.Server.Implementations.Activity
commandText += " LIMIT " + limit.Value.ToString(_usCulture);
}
- var list = new List<ActivityLogEntry>();
+ var statementTexts = new List<string>();
+ statementTexts.Add(commandText);
+ statementTexts.Add("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging);
- using (var statement = connection.PrepareStatement(commandText))
+ connection.RunInTransaction(db =>
{
- if (minDate.HasValue)
- {
- statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
- }
+ var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray())).ToList();
- foreach (var row in statement.ExecuteQuery())
+ using (var statement = statements[0])
{
- list.Add(GetEntry(row));
+ if (minDate.HasValue)
+ {
+ statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
+ }
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(GetEntry(row));
+ }
}
- }
-
- int totalRecordCount;
- using (var statement = connection.PrepareStatement("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging))
- {
- if (minDate.HasValue)
+ using (var statement = statements[1])
{
- statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
- }
+ if (minDate.HasValue)
+ {
+ statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
+ }
- totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
- }
+ totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
+ }
+ }, ReadTransactionMode);
return new QueryResult<ActivityLogEntry>()
{
diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
index 8f2bb2cea..9e60a43aa 100644
--- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
+++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
@@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Data
connectionFlags |= ConnectionFlags.ReadWrite;
}
- //connectionFlags |= ConnectionFlags.SharedCached;
+ connectionFlags |= ConnectionFlags.SharedCached;
connectionFlags |= ConnectionFlags.NoMutex;
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index e3dd3f884..768f5b5a0 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -123,17 +123,10 @@ namespace Emby.Server.Implementations.Data
}
}
- private SQLiteDatabaseConnection _backgroundConnection;
protected override void CloseConnection()
{
base.CloseConnection();
- if (_backgroundConnection != null)
- {
- _backgroundConnection.Dispose();
- _backgroundConnection = null;
- }
-
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
@@ -379,8 +372,6 @@ namespace Emby.Server.Implementations.Data
userDataRepo.Initialize(WriteLock);
- //_backgroundConnection = CreateConnection(true);
-
_shrinkMemoryTimer = _timerFactory.Create(OnShrinkMemoryTimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(30));
}
@@ -1370,6 +1361,10 @@ namespace Emby.Server.Implementations.Data
{
return false;
}
+ if (type == typeof(AudioBook))
+ {
+ return false;
+ }
if (type == typeof(MusicAlbum))
{
return false;
@@ -2691,51 +2686,55 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- var statements = PrepareAllSafe(connection, string.Join(";", statementTexts.ToArray()))
- .ToList();
-
- if (!isReturningZeroItems)
+ connection.RunInTransaction(db =>
{
- using (var statement = statements[0])
+ var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
+ .ToList();
+
+ if (!isReturningZeroItems)
{
- if (EnableJoinUserData(query))
+ using (var statement = statements[0])
{
- statement.TryBind("@UserId", query.User.Id);
- }
+ if (EnableJoinUserData(query))
+ {
+ 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())
- {
- var item = GetItem(row, query);
- if (item != null)
+ foreach (var row in statement.ExecuteQuery())
{
- list.Add(item);
+ var item = GetItem(row, query);
+ if (item != null)
+ {
+ list.Add(item);
+ }
}
}
- }
- }
- if (query.EnableTotalRecordCount)
- {
- using (var statement = statements[statements.Count - 1])
- {
- if (EnableJoinUserData(query))
+ if (query.EnableTotalRecordCount)
{
- statement.TryBind("@UserId", query.User.Id);
- }
+ using (var statement = statements[statements.Count - 1])
+ {
+ if (EnableJoinUserData(query))
+ {
+ 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);
- totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
+ totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
+ }
+ }
}
- }
+
+ }, ReadTransactionMode);
LogQueryTime("GetItems", commandText, now);
@@ -3095,49 +3094,53 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- var statements = PrepareAllSafe(connection, string.Join(";", statementTexts.ToArray()))
- .ToList();
-
var totalRecordCount = 0;
- if (!isReturningZeroItems)
+ connection.RunInTransaction(db =>
{
- using (var statement = statements[0])
+ var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
+ .ToList();
+
+ if (!isReturningZeroItems)
{
- if (EnableJoinUserData(query))
+ using (var statement = statements[0])
{
- statement.TryBind("@UserId", query.User.Id);
- }
+ if (EnableJoinUserData(query))
+ {
+ 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())
- {
- list.Add(row[0].ReadGuid());
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(row[0].ReadGuid());
+ }
}
}
- }
- if (query.EnableTotalRecordCount)
- {
- using (var statement = statements[statements.Count - 1])
+ if (query.EnableTotalRecordCount)
{
- if (EnableJoinUserData(query))
+ using (var statement = statements[statements.Count - 1])
{
- statement.TryBind("@UserId", query.User.Id);
- }
+ if (EnableJoinUserData(query))
+ {
+ 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);
- totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
+ totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
+ }
}
- }
+
+ }, ReadTransactionMode);
LogQueryTime("GetItemIds", commandText, now);
@@ -4426,6 +4429,7 @@ namespace Emby.Server.Implementations.Data
typeof(Movie),
typeof(Playlist),
typeof(AudioPodcast),
+ typeof(AudioBook),
typeof(Trailer),
typeof(BoxSet),
typeof(Episode),
@@ -4594,21 +4598,23 @@ namespace Emby.Server.Implementations.Data
commandText += " order by ListOrder";
var list = new List<string>();
-
using (WriteLock.Read())
{
using (var connection = CreateConnection(true))
{
- using (var statement = PrepareStatementSafe(connection, commandText))
+ connection.RunInTransaction(db =>
{
- // Run this again to bind the params
- GetPeopleWhereClauses(query, statement);
-
- foreach (var row in statement.ExecuteQuery())
+ using (var statement = PrepareStatementSafe(db, commandText))
{
- list.Add(row.GetString(0));
+ // Run this again to bind the params
+ GetPeopleWhereClauses(query, statement);
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(row.GetString(0));
+ }
}
- }
+ }, ReadTransactionMode);
}
return list;
}
@@ -4640,16 +4646,19 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- using (var statement = PrepareStatementSafe(connection, commandText))
+ connection.RunInTransaction(db =>
{
- // Run this again to bind the params
- GetPeopleWhereClauses(query, statement);
-
- foreach (var row in statement.ExecuteQuery())
+ using (var statement = PrepareStatementSafe(db, commandText))
{
- list.Add(GetPerson(row));
+ // Run this again to bind the params
+ GetPeopleWhereClauses(query, statement);
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(GetPerson(row));
+ }
}
- }
+ }, ReadTransactionMode);
}
}
@@ -4855,16 +4864,19 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- using (var statement = PrepareStatementSafe(connection, commandText))
+ connection.RunInTransaction(db =>
{
- foreach (var row in statement.ExecuteQuery())
+ using (var statement = PrepareStatementSafe(db, commandText))
{
- if (!row.IsDBNull(0))
+ foreach (var row in statement.ExecuteQuery())
{
- list.Add(row.GetString(0));
+ if (!row.IsDBNull(0))
+ {
+ list.Add(row.GetString(0));
+ }
}
}
- }
+ }, ReadTransactionMode);
}
}
LogQueryTime("GetItemValueNames", commandText, now);
@@ -5034,69 +5046,72 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- var statements = PrepareAllSafe(connection, string.Join(";", statementTexts.ToArray())).ToList();
-
- if (!isReturningZeroItems)
+ connection.RunInTransaction(db =>
{
- using (var statement = statements[0])
+ var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray())).ToList();
+
+ if (!isReturningZeroItems)
{
- statement.TryBind("@SelectType", returnType);
- if (EnableJoinUserData(query))
+ using (var statement = statements[0])
{
- statement.TryBind("@UserId", query.User.Id);
- }
+ statement.TryBind("@SelectType", returnType);
+ if (EnableJoinUserData(query))
+ {
+ statement.TryBind("@UserId", query.User.Id);
+ }
- if (typeSubQuery != null)
- {
- GetWhereClauses(typeSubQuery, null, "itemTypes");
- }
- BindSimilarParams(query, statement);
- GetWhereClauses(innerQuery, statement);
- GetWhereClauses(outerQuery, statement);
+ if (typeSubQuery != null)
+ {
+ GetWhereClauses(typeSubQuery, null, "itemTypes");
+ }
+ BindSimilarParams(query, statement);
+ GetWhereClauses(innerQuery, statement);
+ GetWhereClauses(outerQuery, statement);
- foreach (var row in statement.ExecuteQuery())
- {
- var item = GetItem(row);
- if (item != null)
+ foreach (var row in statement.ExecuteQuery())
{
- var countStartColumn = columns.Count - 1;
+ var item = GetItem(row);
+ if (item != null)
+ {
+ var countStartColumn = columns.Count - 1;
- list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
+ list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
+ }
}
- }
- LogQueryTime("GetItemValues", commandText, now);
+ LogQueryTime("GetItemValues", commandText, now);
+ }
}
- }
- if (query.EnableTotalRecordCount)
- {
- commandText = "select count (distinct PresentationUniqueKey)" + GetFromText();
+ if (query.EnableTotalRecordCount)
+ {
+ commandText = "select count (distinct PresentationUniqueKey)" + GetFromText();
- commandText += GetJoinUserDataText(query);
- commandText += whereText;
+ commandText += GetJoinUserDataText(query);
+ commandText += whereText;
- using (var statement = statements[statements.Count - 1])
- {
- statement.TryBind("@SelectType", returnType);
- if (EnableJoinUserData(query))
+ using (var statement = statements[statements.Count - 1])
{
- statement.TryBind("@UserId", query.User.Id);
- }
+ statement.TryBind("@SelectType", returnType);
+ if (EnableJoinUserData(query))
+ {
+ statement.TryBind("@UserId", query.User.Id);
+ }
- if (typeSubQuery != null)
- {
- GetWhereClauses(typeSubQuery, null, "itemTypes");
- }
- BindSimilarParams(query, statement);
- GetWhereClauses(innerQuery, statement);
- GetWhereClauses(outerQuery, statement);
+ if (typeSubQuery != null)
+ {
+ GetWhereClauses(typeSubQuery, null, "itemTypes");
+ }
+ BindSimilarParams(query, statement);
+ GetWhereClauses(innerQuery, statement);
+ GetWhereClauses(outerQuery, statement);
- count = statement.ExecuteQuery().SelectScalarInt().First();
+ count = statement.ExecuteQuery().SelectScalarInt().First();
- LogQueryTime("GetItemValues", commandText, now);
+ LogQueryTime("GetItemValues", commandText, now);
+ }
}
- }
+ }, ReadTransactionMode);
}
}
@@ -5344,25 +5359,28 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- using (var statement = PrepareStatementSafe(connection, cmdText))
+ connection.RunInTransaction(db =>
{
- statement.TryBind("@ItemId", query.ItemId.ToGuidParamValue());
-
- if (query.Type.HasValue)
+ using (var statement = PrepareStatementSafe(db, cmdText))
{
- statement.TryBind("@StreamType", query.Type.Value.ToString());
- }
+ statement.TryBind("@ItemId", query.ItemId.ToGuidParamValue());
- if (query.Index.HasValue)
- {
- statement.TryBind("@StreamIndex", query.Index.Value);
- }
+ if (query.Type.HasValue)
+ {
+ statement.TryBind("@StreamType", query.Type.Value.ToString());
+ }
- foreach (var row in statement.ExecuteQuery())
- {
- list.Add(GetMediaStream(row));
+ if (query.Index.HasValue)
+ {
+ statement.TryBind("@StreamIndex", query.Index.Value);
+ }
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(GetMediaStream(row));
+ }
}
- }
+ }, ReadTransactionMode);
}
}
diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
index be59d71b3..7afb5720e 100644
--- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
@@ -300,20 +300,26 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
- {
- statement.TryBind("@UserId", userId.ToGuidParamValue());
- statement.TryBind("@Key", key);
+ UserItemData result = null;
- foreach (var row in statement.ExecuteQuery())
+ connection.RunInTransaction(db =>
+ {
+ using (var statement = db.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
{
- return ReadRow(row);
+ statement.TryBind("@UserId", userId.ToGuidParamValue());
+ statement.TryBind("@Key", key);
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ result = ReadRow(row);
+ break;
+ }
}
- }
+ }, ReadTransactionMode);
+
+ return result;
}
}
-
- return null;
}
public UserItemData GetUserData(Guid userId, List<string> keys)
diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
index 47f4e7ced..e478b9d81 100644
--- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj
+++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
@@ -119,6 +119,7 @@
<Compile Include="Library\Resolvers\Audio\MusicAlbumResolver.cs" />
<Compile Include="Library\Resolvers\Audio\MusicArtistResolver.cs" />
<Compile Include="Library\Resolvers\BaseVideoResolver.cs" />
+ <Compile Include="Library\Resolvers\Books\BookResolver.cs" />
<Compile Include="Library\Resolvers\FolderResolver.cs" />
<Compile Include="Library\Resolvers\ItemResolver.cs" />
<Compile Include="Library\Resolvers\Movies\BoxSetResolver.cs" />
diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs
index d8805355a..2e3d81474 100644
--- a/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs
+++ b/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs
@@ -2,6 +2,7 @@
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using System;
+using MediaBrowser.Controller.Entities;
namespace Emby.Server.Implementations.Library.Resolvers.Audio
{
@@ -59,6 +60,11 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
{
return new MediaBrowser.Controller.Entities.Audio.Audio();
}
+
+ if (string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
+ {
+ return new AudioBook();
+ }
}
}
diff --git a/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs
new file mode 100644
index 000000000..4852c3c6a
--- /dev/null
+++ b/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs
@@ -0,0 +1,77 @@
+using System;
+using System.IO;
+using System.Linq;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Model.Entities;
+
+namespace Emby.Server.Implementations.Library.Resolvers.Books
+{
+ /// <summary>
+ ///
+ /// </summary>
+ public class BookResolver : MediaBrowser.Controller.Resolvers.ItemResolver<Book>
+ {
+ private readonly string[] _validExtensions = {".pdf", ".epub", ".mobi", ".cbr", ".cbz"};
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="args"></param>
+ /// <returns></returns>
+ protected override Book Resolve(ItemResolveArgs args)
+ {
+ var collectionType = args.GetCollectionType();
+
+ // Only process items that are in a collection folder containing books
+ if (!string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
+ return null;
+
+ if (args.IsDirectory)
+ {
+ return GetBook(args);
+ }
+
+ var extension = Path.GetExtension(args.Path);
+
+ if (extension != null && _validExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
+ {
+ // It's a book
+ return new Book
+ {
+ Path = args.Path,
+ IsInMixedFolder = true
+ };
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="args"></param>
+ /// <returns></returns>
+ private Book GetBook(ItemResolveArgs args)
+ {
+ var bookFiles = args.FileSystemChildren.Where(f =>
+ {
+ var fileExtension = Path.GetExtension(f.FullName) ??
+ string.Empty;
+
+ return _validExtensions.Contains(fileExtension,
+ StringComparer
+ .OrdinalIgnoreCase);
+ }).ToList();
+
+ // Don't return a Book if there is more (or less) than one document in the directory
+ if (bookFiles.Count != 1)
+ return null;
+
+ return new Book
+ {
+ Path = bookFiles[0].FullName
+ };
+ }
+ }
+}
diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs
index c8dde1287..f4a30fc00 100644
--- a/Emby.Server.Implementations/Library/UserDataManager.cs
+++ b/Emby.Server.Implementations/Library/UserDataManager.cs
@@ -274,7 +274,7 @@ namespace Emby.Server.Implementations.Library
positionTicks = 0;
data.Played = false;
}
- if (item is Audio)
+ if (!item.SupportsPositionTicksResume)
{
positionTicks = 0;
}
diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs
index dbca4931b..a136701da 100644
--- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs
+++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs
@@ -201,35 +201,47 @@ namespace Emby.Server.Implementations.Security
}
var list = new List<AuthenticationInfo>();
+ int totalRecordCount = 0;
using (WriteLock.Read())
{
using (var connection = CreateConnection(true))
{
- using (var statement = connection.PrepareStatement(commandText))
+ connection.RunInTransaction(db =>
{
- BindAuthenticationQueryParams(query, statement);
+ var statementTexts = new List<string>();
+ statementTexts.Add(commandText);
+ statementTexts.Add("select count (Id) from AccessTokens" + whereTextWithoutPaging);
- foreach (var row in statement.ExecuteQuery())
- {
- list.Add(Get(row));
- }
+ var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
+ .ToList();
- using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
+ using (var statement = statements[0])
{
- BindAuthenticationQueryParams(query, totalCountStatement);
+ BindAuthenticationQueryParams(query, statement);
- var count = totalCountStatement.ExecuteQuery()
- .SelectScalarInt()
- .First();
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(Get(row));
+ }
- return new QueryResult<AuthenticationInfo>()
+ using (var totalCountStatement = statements[1])
{
- Items = list.ToArray(),
- TotalRecordCount = count
- };
+ BindAuthenticationQueryParams(query, totalCountStatement);
+
+ totalRecordCount = totalCountStatement.ExecuteQuery()
+ .SelectScalarInt()
+ .First();
+ }
}
- }
+
+ }, ReadTransactionMode);
+
+ return new QueryResult<AuthenticationInfo>()
+ {
+ Items = list.ToArray(),
+ TotalRecordCount = totalRecordCount
+ };
}
}
}
diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs
index 4f876f6a3..88d224525 100644
--- a/Emby.Server.Implementations/TV/TVSeriesManager.cs
+++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs
@@ -62,7 +62,14 @@ namespace Emby.Server.Implementations.TV
PresentationUniqueKey = presentationUniqueKey,
Limit = limit,
ParentId = parentIdGuid,
- Recursive = true
+ Recursive = true,
+ DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
+ {
+ Fields = new List<ItemFields>
+ {
+
+ }
+ }
}).Cast<Series>();
@@ -104,7 +111,15 @@ namespace Emby.Server.Implementations.TV
IncludeItemTypes = new[] { typeof(Series).Name },
SortOrder = SortOrder.Ascending,
PresentationUniqueKey = presentationUniqueKey,
- Limit = limit
+ Limit = limit,
+ DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
+ {
+ Fields = new List<ItemFields>
+ {
+
+ },
+ EnableImages = false
+ }
}, parentsFolders.Cast<BaseItem>().ToList()).Cast<Series>();
@@ -120,26 +135,32 @@ namespace Emby.Server.Implementations.TV
var currentUser = user;
var allNextUp = series
- .Select(i => GetNextUp(i, currentUser))
+ .Select(i => GetNextUp(GetUniqueSeriesKey(i), currentUser))
// Include if an episode was found, and either the series is not unwatched or the specific series was requested
- .OrderByDescending(i => i.Item1)
- .ToList();
+ .OrderByDescending(i => i.Item1);
// If viewing all next up for all series, remove first episodes
- if (string.IsNullOrWhiteSpace(request.SeriesId))
- {
- var withoutFirstEpisode = allNextUp
- .Where(i => i.Item1 != DateTime.MinValue)
- .ToList();
-
- // But if that returns empty, keep those first episodes (avoid completely empty view)
- if (withoutFirstEpisode.Count > 0)
- {
- allNextUp = withoutFirstEpisode;
- }
- }
+ // But if that returns empty, keep those first episodes (avoid completely empty view)
+ var alwaysEnableFirstEpisode = string.IsNullOrWhiteSpace(request.SeriesId);
+ var isFirstItemAFirstEpisode = true;
return allNextUp
+ .Where(i =>
+ {
+ if (alwaysEnableFirstEpisode || i.Item1 != DateTime.MinValue)
+ {
+ isFirstItemAFirstEpisode = false;
+ return true;
+ }
+
+ if (isFirstItemAFirstEpisode)
+ {
+ return false;
+ }
+
+ return true;
+ })
+ .Take(request.Limit.HasValue ? (request.Limit.Value * 2) : int.MaxValue)
.Select(i => i.Item2())
.Where(i => i != null)
.Take(request.Limit ?? int.MaxValue);
@@ -153,13 +174,10 @@ namespace Emby.Server.Implementations.TV
/// <summary>
/// Gets the next up.
/// </summary>
- /// <param name="series">The series.</param>
- /// <param name="user">The user.</param>
/// <returns>Task{Episode}.</returns>
- private Tuple<DateTime, Func<Episode>> GetNextUp(Series series, User user)
+ private Tuple<DateTime, Func<Episode>> GetNextUp(string seriesKey, User user)
{
var enableSeriesPresentationKey = _config.Configuration.EnableSeriesPresentationUniqueKey;
- var seriesKey = GetUniqueSeriesKey(series);
var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user)
{
@@ -170,7 +188,15 @@ namespace Emby.Server.Implementations.TV
SortOrder = SortOrder.Descending,
IsPlayed = true,
Limit = 1,
- ParentIndexNumberNotEquals = 0
+ ParentIndexNumberNotEquals = 0,
+ DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
+ {
+ Fields = new List<ItemFields>
+ {
+
+ },
+ EnableImages = false
+ }
}).FirstOrDefault();