From 1aff48b93b72fe7d418b4798f504bd0d145f44e8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 12 Dec 2016 00:49:19 -0500 Subject: move book support into the core --- .../Security/AuthenticationRepository.cs | 44 ++++++++++++++-------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'Emby.Server.Implementations/Security/AuthenticationRepository.cs') 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(); + 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(); + 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() + using (var totalCountStatement = statements[1]) { - Items = list.ToArray(), - TotalRecordCount = count - }; + BindAuthenticationQueryParams(query, totalCountStatement); + + totalRecordCount = totalCountStatement.ExecuteQuery() + .SelectScalarInt() + .First(); + } } - } + + }, ReadTransactionMode); + + return new QueryResult() + { + Items = list.ToArray(), + TotalRecordCount = totalRecordCount + }; } } } -- cgit v1.2.3