From 1c52e4f51b1a9732264203fb0d987cf9752ef45b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 28 Nov 2016 14:26:48 -0500 Subject: [PATCH] update transaction modes --- .../Activity/ActivityRepository.cs | 2 +- .../Data/BaseSqliteRepository.cs | 5 +++++ .../Data/SqliteDisplayPreferencesRepository.cs | 4 ++-- .../Data/SqliteFileOrganizationRepository.cs | 6 +++--- .../Data/SqliteItemRepository.cs | 8 ++++---- .../Data/SqliteUserDataRepository.cs | 10 +++++----- .../Data/SqliteUserRepository.cs | 4 ++-- .../SqliteNotificationsRepository.cs | 6 +++--- .../Security/AuthenticationRepository.cs | 18 ++++++++++-------- .../Social/SharingRepository.cs | 2 +- .../Sync/SyncRepository.cs | 8 ++++---- 11 files changed, 40 insertions(+), 33 deletions(-) diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index ba81992ac..f7419de80 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Activity statement.MoveNext(); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index 308b8356f..af8de0e84 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -30,6 +30,11 @@ namespace Emby.Server.Implementations.Data get { return false; } } + protected TransactionMode TransactionMode + { + get { return TransactionMode.Immediate; } + } + static BaseSqliteRepository() { SQLite3.EnableSharedCache = false; diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs index 1bd64b21d..743186db2 100644 --- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs @@ -100,7 +100,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { SaveDisplayPreferences(displayPreferences, userId, client, db); - }); + }, TransactionMode); } } } @@ -147,7 +147,7 @@ namespace Emby.Server.Implementations.Data { SaveDisplayPreferences(displayPreference, userId, displayPreference.Client, db); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs index 23bab883e..448d38c8c 100644 --- a/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteFileOrganizationRepository.cs @@ -85,7 +85,7 @@ namespace Emby.Server.Implementations.Data statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -108,7 +108,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@ResultId", id.ToGuidParamValue()); statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -124,7 +124,7 @@ namespace Emby.Server.Implementations.Data var commandText = "delete from FileOrganizerResults"; db.Execute(commandText); - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 29aacc059..54820ab53 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -316,7 +316,7 @@ namespace Emby.Server.Implementations.Data AddColumn(db, "MediaStreams", "RefFrames", "INT", existingColumnNames); AddColumn(db, "MediaStreams", "KeyFrames", "TEXT", existingColumnNames); AddColumn(db, "MediaStreams", "IsAnamorphic", "BIT", existingColumnNames); - }); + }, TransactionMode); string[] postQueries = @@ -697,7 +697,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { SaveItemsInTranscation(db, tuples); - }); + }, TransactionMode); } } } @@ -2211,7 +2211,7 @@ namespace Emby.Server.Implementations.Data index++; } } - }); + }, TransactionMode); } } } @@ -4531,7 +4531,7 @@ namespace Emby.Server.Implementations.Data // Delete the item ExecuteWithSingleParam(db, "delete from TypedBaseItems where guid=@Id", id.ToGuidParamValue()); - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index b01f215e0..f7184540a 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Data AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); - }); + }, TransactionMode); ImportUserDataIfNeeded(connection); } @@ -116,7 +116,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@IsUserDataImported", true); statement.MoveNext(); } - }); + }, TransactionMode); } private void ImportUserData(IDatabaseConnection connection, string file) @@ -128,7 +128,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { db.Execute("REPLACE INTO userdata(" + columns + ") SELECT " + columns + " FROM UserDataBackup.userdata;"); - }); + }, TransactionMode); } /// @@ -197,7 +197,7 @@ namespace Emby.Server.Implementations.Data connection.RunInTransaction(db => { SaveUserData(db, userId, key, userData); - }); + }, TransactionMode); } } } @@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.Data { SaveUserData(db, userId, userItemData.Key, userItemData); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs index f902d981f..5fb27d081 100644 --- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs @@ -102,7 +102,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@data", serialized); statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -164,7 +164,7 @@ namespace Emby.Server.Implementations.Data statement.TryBind("@id", user.Id.ToGuidParamValue()); statement.MoveNext(); } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs index 66ef5d5d1..5f0d4d29a 100644 --- a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs +++ b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs @@ -249,7 +249,7 @@ namespace Emby.Server.Implementations.Notifications statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -304,7 +304,7 @@ namespace Emby.Server.Implementations.Notifications statement.MoveNext(); } - }); + }, TransactionMode); } } } @@ -334,7 +334,7 @@ namespace Emby.Server.Implementations.Notifications } } - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs index 2632b9666..e498253c3 100644 --- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs +++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs @@ -50,7 +50,8 @@ namespace Emby.Server.Implementations.Security var existingColumnNames = GetColumnNames(db, "AccessTokens"); AddColumn(db, "AccessTokens", "AppVersion", "TEXT", existingColumnNames); - }); + + }, TransactionMode); } } @@ -70,9 +71,9 @@ namespace Emby.Server.Implementations.Security cancellationToken.ThrowIfCancellationRequested(); - using (WriteLock.Write()) + using (var connection = CreateConnection()) { - using (var connection = CreateConnection()) + using (WriteLock.Write()) { connection.RunInTransaction(db => { @@ -100,7 +101,8 @@ namespace Emby.Server.Implementations.Security statement.MoveNext(); } - }); + + }, TransactionMode); } } } @@ -137,9 +139,9 @@ namespace Emby.Server.Implementations.Security throw new ArgumentNullException("query"); } - using (WriteLock.Read()) + using (var connection = CreateConnection(true)) { - using (var connection = CreateConnection(true)) + using (WriteLock.Read()) { var commandText = BaseSelectText; @@ -244,9 +246,9 @@ namespace Emby.Server.Implementations.Security throw new ArgumentNullException("id"); } - using (WriteLock.Read()) + using (var connection = CreateConnection(true)) { - using (var connection = CreateConnection(true)) + using (WriteLock.Read()) { var commandText = BaseSelectText + " where Id=@Id"; diff --git a/Emby.Server.Implementations/Social/SharingRepository.cs b/Emby.Server.Implementations/Social/SharingRepository.cs index 6dab54bc6..71f80a575 100644 --- a/Emby.Server.Implementations/Social/SharingRepository.cs +++ b/Emby.Server.Implementations/Social/SharingRepository.cs @@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.Social info.ItemId, info.UserId, info.ExpirationDate.ToDateTimeParamValue()); - }); + }, TransactionMode); } } } diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index b2d9fbcc9..caf98e666 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Sync existingColumnNames = GetColumnNames(db, "SyncJobItems"); AddColumn(db, "SyncJobItems", "ItemDateModifiedTicks", "BIGINT", existingColumnNames); - }); + }, TransactionMode); } } @@ -268,7 +268,7 @@ namespace Emby.Server.Implementations.Sync connection.RunInTransaction(conn => { conn.Execute(commandText, paramList.ToArray()); - }); + }, TransactionMode); } } } @@ -290,7 +290,7 @@ namespace Emby.Server.Implementations.Sync { conn.Execute("delete from SyncJobs where Id=?", id.ToGuidParamValue()); conn.Execute("delete from SyncJobItems where JobId=?", id); - }); + }, TransactionMode); } } } @@ -743,7 +743,7 @@ namespace Emby.Server.Implementations.Sync connection.RunInTransaction(conn => { conn.Execute(commandText, paramList.ToArray()); - }); + }, TransactionMode); } } }