aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-05 16:49:14 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-05 16:49:14 -0400
commit9794c8fb1adc01823a9bdd469b470390fee0ebcd (patch)
treeb2780708fdb202bd6c501687c79429d0670407a5
parentf4f3d1255e34bced614e125dc8d8b05c29e41ead (diff)
#99 - Active user list wrong
-rw-r--r--MediaBrowser.Server.Implementations/Library/UserManager.cs38
-rw-r--r--MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs12
-rw-r--r--MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs48
3 files changed, 63 insertions, 35 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs
index 682ec9a8c..9293d8199 100644
--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs
@@ -25,8 +25,8 @@ namespace MediaBrowser.Server.Implementations.Library
/// <summary>
/// The _active connections
/// </summary>
- private readonly List<ClientConnectionInfo> _activeConnections =
- new List<ClientConnectionInfo>();
+ private readonly ConcurrentDictionary<string, ClientConnectionInfo> _activeConnections =
+ new ConcurrentDictionary<string, ClientConnectionInfo>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// The _users
@@ -69,7 +69,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <value>All connections.</value>
public IEnumerable<ClientConnectionInfo> AllConnections
{
- get { return _activeConnections.Where(c => GetUserById(c.UserId) != null).OrderByDescending(c => c.LastActivityDate); }
+ get { return _activeConnections.Values.OrderByDescending(c => c.LastActivityDate); }
}
/// <summary>
@@ -313,29 +313,19 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>ClientConnectionInfo.</returns>
private ClientConnectionInfo GetConnection(Guid userId, string clientType, string deviceId, string deviceName)
{
- lock (_activeConnections)
- {
- var conn = _activeConnections.FirstOrDefault(c => string.Equals(c.Client, clientType, StringComparison.OrdinalIgnoreCase) && string.Equals(deviceId, c.DeviceId));
+ var key = clientType + deviceId;
- if (conn == null)
- {
- conn = new ClientConnectionInfo
- {
- UserId = userId,
- Client = clientType,
- DeviceName = deviceName,
- DeviceId = deviceId
- };
-
- _activeConnections.Add(conn);
- }
- else
- {
- conn.UserId = userId;
- }
+ var connection = _activeConnections.GetOrAdd(key, keyName => new ClientConnectionInfo
+ {
+ UserId = userId,
+ Client = clientType,
+ DeviceName = deviceName,
+ DeviceId = deviceId
+ });
- return conn;
- }
+ connection.UserId = userId;
+
+ return connection;
}
/// <summary>
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs
index c6f35a978..f471365ce 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs
@@ -34,6 +34,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
}
/// <summary>
+ /// Gets a value indicating whether [enable delayed commands].
+ /// </summary>
+ /// <value><c>true</c> if [enable delayed commands]; otherwise, <c>false</c>.</value>
+ protected override bool EnableDelayedCommands
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
/// The _protobuf serializer
/// </summary>
private readonly IProtobufSerializer _protobufSerializer;
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
@@ -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>