aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Security/AuthenticationRepository.cs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2019-08-18 22:05:06 +0200
committerBond_009 <bond.009@outlook.com>2019-08-18 22:05:06 +0200
commitf70a63d5759c5c9a3e0127a89763a3f644970634 (patch)
tree11c7bb9b8283dc745354196f3e824c110beb12b9 /Emby.Server.Implementations/Security/AuthenticationRepository.cs
parent4bb0c2d0532e345f467f6cbee77a78851d26e386 (diff)
Return DB asap
Diffstat (limited to 'Emby.Server.Implementations/Security/AuthenticationRepository.cs')
-rw-r--r--Emby.Server.Implementations/Security/AuthenticationRepository.cs85
1 files changed, 43 insertions, 42 deletions
diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs
index 0b5ee5d03..1ef5c4b99 100644
--- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs
+++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs
@@ -23,22 +23,22 @@ namespace Emby.Server.Implementations.Security
public void Initialize()
{
- using (var connection = GetConnection())
+ string[] queries =
{
- var tableNewlyCreated = !TableExists(connection, "Tokens");
+ "create table if not exists Tokens (Id INTEGER PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT NOT NULL, AppName TEXT NOT NULL, AppVersion TEXT NOT NULL, DeviceName TEXT NOT NULL, UserId TEXT, UserName TEXT, IsActive BIT NOT NULL, DateCreated DATETIME NOT NULL, DateLastActivity DATETIME NOT NULL)",
+ "create table if not exists Devices (Id TEXT NOT NULL PRIMARY KEY, CustomName TEXT, Capabilities TEXT)",
+ "drop index if exists idx_AccessTokens",
+ "drop index if exists Tokens1",
+ "drop index if exists Tokens2",
- string[] queries = {
-
- "create table if not exists Tokens (Id INTEGER PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT NOT NULL, AppName TEXT NOT NULL, AppVersion TEXT NOT NULL, DeviceName TEXT NOT NULL, UserId TEXT, UserName TEXT, IsActive BIT NOT NULL, DateCreated DATETIME NOT NULL, DateLastActivity DATETIME NOT NULL)",
- "create table if not exists Devices (Id TEXT NOT NULL PRIMARY KEY, CustomName TEXT, Capabilities TEXT)",
+ "create index if not exists Tokens3 on Tokens (AccessToken, DateLastActivity)",
+ "create index if not exists Tokens4 on Tokens (Id, DateLastActivity)",
+ "create index if not exists Devices1 on Devices (Id)"
+ };
- "drop index if exists idx_AccessTokens",
- "drop index if exists Tokens1",
- "drop index if exists Tokens2",
- "create index if not exists Tokens3 on Tokens (AccessToken, DateLastActivity)",
- "create index if not exists Tokens4 on Tokens (Id, DateLastActivity)",
- "create index if not exists Devices1 on Devices (Id)"
- };
+ using (var connection = GetConnection())
+ {
+ var tableNewlyCreated = !TableExists(connection, "Tokens");
connection.RunQueries(queries);
@@ -244,45 +244,46 @@ namespace Emby.Server.Implementations.Security
}
}
- var list = new List<AuthenticationInfo>();
+ var statementTexts = new[]
+ {
+ commandText,
+ "select count (Id) from Tokens" + whereTextWithoutPaging
+ };
+ var list = new List<AuthenticationInfo>();
+ var result = new QueryResult<AuthenticationInfo>();
using (var connection = GetConnection(true))
{
- return connection.RunInTransaction(db =>
- {
- var result = new QueryResult<AuthenticationInfo>();
-
- var statementTexts = new List<string>();
- statementTexts.Add(commandText);
- statementTexts.Add("select count (Id) from Tokens" + whereTextWithoutPaging);
-
- var statements = PrepareAll(db, statementTexts)
- .ToList();
-
- using (var statement = statements[0])
+ connection.RunInTransaction(
+ db =>
{
- BindAuthenticationQueryParams(query, statement);
+ var statements = PrepareAll(db, statementTexts)
+ .ToList();
- foreach (var row in statement.ExecuteQuery())
+ using (var statement = statements[0])
{
- list.Add(Get(row));
- }
+ BindAuthenticationQueryParams(query, statement);
- using (var totalCountStatement = statements[1])
- {
- BindAuthenticationQueryParams(query, totalCountStatement);
-
- result.TotalRecordCount = totalCountStatement.ExecuteQuery()
- .SelectScalarInt()
- .First();
- }
- }
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(Get(row));
+ }
- result.Items = list.ToArray();
- return result;
+ using (var totalCountStatement = statements[1])
+ {
+ BindAuthenticationQueryParams(query, totalCountStatement);
- }, ReadTransactionMode);
+ result.TotalRecordCount = totalCountStatement.ExecuteQuery()
+ .SelectScalarInt()
+ .First();
+ }
+ }
+ },
+ ReadTransactionMode);
}
+
+ result.Items = list.ToArray();
+ return result;
}
private static AuthenticationInfo Get(IReadOnlyList<IResultSetValue> reader)