From 9794c8fb1adc01823a9bdd469b470390fee0ebcd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Apr 2013 16:49:14 -0400 Subject: #99 - Active user list wrong --- .../Sqlite/SQLiteRepository.cs | 48 +++++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs') diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs index c5320a1f6..376cf5065 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs @@ -43,6 +43,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite /// The logger. protected ILogger Logger { get; private set; } + /// + /// Gets a value indicating whether [enable delayed commands]. + /// + /// true if [enable delayed commands]; otherwise, false. + protected virtual bool EnableDelayedCommands + { + get + { + return true; + } + } + /// /// Initializes a new instance of the class. /// @@ -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)); + } } /// @@ -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()) @@ -181,6 +189,24 @@ namespace MediaBrowser.Server.Implementations.Sqlite } } + /// + /// Flushes the on dispose. + /// + 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); + } + } + /// /// Queues the command. /// -- cgit v1.2.3