diff options
| author | Techywarrior <techywarrior@gmail.com> | 2013-04-05 19:45:32 -0700 |
|---|---|---|
| committer | Techywarrior <techywarrior@gmail.com> | 2013-04-05 19:45:32 -0700 |
| commit | 51b71afd5cfcaa6db606073a24c4c891cdf46cb3 (patch) | |
| tree | b801589b7e167125b7fae7add6b9a914daeeaa10 /MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs | |
| parent | 7c3f257581344aadf6f697f3159becbd613db7e2 (diff) | |
| parent | 9c7f492e2cd3b940d8041e6949cea9898a057826 (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs index c5320a1f6..e722ac3dc 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs @@ -30,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite /// <summary> /// The flush interval /// </summary> - private const int FlushInterval = 5000; + private const int FlushInterval = 2000; /// <summary> /// The flush timer @@ -44,6 +44,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite protected ILogger Logger { get; private set; } /// <summary> + /// Gets a value indicating whether [enable delayed commands]. + /// </summary> + /// <value><c>true</c> if [enable delayed commands]; otherwise, <c>false</c>.</value> + protected virtual bool EnableDelayedCommands + { + get + { + return true; + } + } + + /// <summary> /// Initializes a new instance of the <see cref="SqliteRepository" /> class. /// </summary> /// <param name="logManager">The log manager.</param> @@ -85,8 +97,11 @@ namespace MediaBrowser.Server.Implementations.Sqlite await connection.OpenAsync().ConfigureAwait(false); - // Run once - FlushTimer = new Timer(Flush, null, TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1)); + if (EnableDelayedCommands) + { + // Run once + FlushTimer = new Timer(Flush, null, TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1)); + } } /// <summary> @@ -147,16 +162,9 @@ namespace MediaBrowser.Server.Implementations.Sqlite { if (connection != null) { - // If we're not already flushing, do it now - if (!IsFlushing) - { - Flush(null); - } - - // Don't dispose in the middle of a flush - while (IsFlushing) + if (EnableDelayedCommands) { - Thread.Sleep(25); + FlushOnDispose(); } if (connection.IsOpen()) @@ -182,6 +190,24 @@ namespace MediaBrowser.Server.Implementations.Sqlite } /// <summary> + /// Flushes the on dispose. + /// </summary> + private void FlushOnDispose() + { + // If we're not already flushing, do it now + if (!IsFlushing) + { + Flush(null); + } + + // Don't dispose in the middle of a flush + while (IsFlushing) + { + Thread.Sleep(25); + } + } + + /// <summary> /// Queues the command. /// </summary> /// <param name="cmd">The CMD.</param> |
