#99 - Active user list wrong

pull/702/head
Luke Pulverenti 12 years ago
parent f4f3d1255e
commit 9794c8fb1a

@ -25,8 +25,8 @@ namespace MediaBrowser.Server.Implementations.Library
/// <summary> /// <summary>
/// The _active connections /// The _active connections
/// </summary> /// </summary>
private readonly List<ClientConnectionInfo> _activeConnections = private readonly ConcurrentDictionary<string, ClientConnectionInfo> _activeConnections =
new List<ClientConnectionInfo>(); new ConcurrentDictionary<string, ClientConnectionInfo>(StringComparer.OrdinalIgnoreCase);
/// <summary> /// <summary>
/// The _users /// The _users
@ -69,7 +69,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <value>All connections.</value> /// <value>All connections.</value>
public IEnumerable<ClientConnectionInfo> AllConnections 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> /// <summary>
@ -313,29 +313,19 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>ClientConnectionInfo.</returns> /// <returns>ClientConnectionInfo.</returns>
private ClientConnectionInfo GetConnection(Guid userId, string clientType, string deviceId, string deviceName) private ClientConnectionInfo GetConnection(Guid userId, string clientType, string deviceId, string deviceName)
{ {
lock (_activeConnections) var key = clientType + deviceId;
{
var conn = _activeConnections.FirstOrDefault(c => string.Equals(c.Client, clientType, StringComparison.OrdinalIgnoreCase) && string.Equals(deviceId, c.DeviceId));
if (conn == null) var connection = _activeConnections.GetOrAdd(key, keyName => new ClientConnectionInfo
{
conn = new ClientConnectionInfo
{ {
UserId = userId, UserId = userId,
Client = clientType, Client = clientType,
DeviceName = deviceName, DeviceName = deviceName,
DeviceId = deviceId DeviceId = deviceId
}; });
_activeConnections.Add(conn); connection.UserId = userId;
}
else
{
conn.UserId = userId;
}
return conn; return connection;
}
} }
/// <summary> /// <summary>

@ -33,6 +33,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> /// <summary>
/// The _protobuf serializer /// The _protobuf serializer
/// </summary> /// </summary>

@ -43,6 +43,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <value>The logger.</value> /// <value>The logger.</value>
protected ILogger Logger { get; private set; } 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> /// <summary>
/// Initializes a new instance of the <see cref="SqliteRepository" /> class. /// Initializes a new instance of the <see cref="SqliteRepository" /> class.
/// </summary> /// </summary>
@ -85,9 +97,12 @@ namespace MediaBrowser.Server.Implementations.Sqlite
await connection.OpenAsync().ConfigureAwait(false); await connection.OpenAsync().ConfigureAwait(false);
if (EnableDelayedCommands)
{
// Run once // Run once
FlushTimer = new Timer(Flush, null, TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1)); FlushTimer = new Timer(Flush, null, TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1));
} }
}
/// <summary> /// <summary>
/// Runs the queries. /// Runs the queries.
@ -147,16 +162,9 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{ {
if (connection != null) if (connection != null)
{ {
// If we're not already flushing, do it now if (EnableDelayedCommands)
if (!IsFlushing)
{
Flush(null);
}
// Don't dispose in the middle of a flush
while (IsFlushing)
{ {
Thread.Sleep(25); FlushOnDispose();
} }
if (connection.IsOpen()) if (connection.IsOpen())
@ -181,6 +189,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> /// <summary>
/// Queues the command. /// Queues the command.
/// </summary> /// </summary>

Loading…
Cancel
Save