mirror of https://github.com/jellyfin/jellyfin.git
update user data db
This commit is contained in:
parent
2107736584
commit
96b1ddfddf
|
@ -45,8 +45,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var cmd = connection.CreateCommand())
|
using (var cmd = connection.CreateCommand())
|
||||||
|
@ -61,10 +59,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
WriteLock.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly object _disposeLock = new object();
|
private readonly object _disposeLock = new object();
|
||||||
|
|
|
@ -15,12 +15,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||||
{
|
{
|
||||||
private IDbConnection _connection;
|
|
||||||
private readonly IApplicationPaths _appPaths;
|
|
||||||
|
|
||||||
public SqliteUserDataRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
public SqliteUserDataRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
||||||
{
|
{
|
||||||
_appPaths = appPaths;
|
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -41,10 +38,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public async Task Initialize(IDbConnector dbConnector)
|
public async Task Initialize(IDbConnector dbConnector)
|
||||||
{
|
{
|
||||||
var dbFile = Path.Combine(_appPaths.DataPath, "userdata_v2.db");
|
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||||
|
{
|
||||||
_connection = await dbConnector.Connect(dbFile, false).ConfigureAwait(false);
|
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
"create table if not exists userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
||||||
|
@ -58,10 +53,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
"pragma shrink_memory"
|
"pragma shrink_memory"
|
||||||
};
|
};
|
||||||
|
|
||||||
_connection.RunQueries(queries, Logger);
|
connection.RunQueries(queries, Logger);
|
||||||
|
|
||||||
_connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
|
connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
|
||||||
_connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
|
connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -123,15 +119,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||||
|
{
|
||||||
IDbTransaction transaction = null;
|
IDbTransaction transaction = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
transaction = _connection.BeginTransaction();
|
transaction = connection.BeginTransaction();
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
||||||
|
|
||||||
|
@ -179,8 +175,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
transaction.Dispose();
|
transaction.Dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
WriteLock.Release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,17 +190,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||||
|
{
|
||||||
IDbTransaction transaction = null;
|
IDbTransaction transaction = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
transaction = _connection.BeginTransaction();
|
transaction = connection.BeginTransaction();
|
||||||
|
|
||||||
foreach (var userItemData in userData)
|
foreach (var userItemData in userData)
|
||||||
{
|
{
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
||||||
|
|
||||||
|
@ -256,8 +251,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
transaction.Dispose();
|
transaction.Dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
WriteLock.Release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +277,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
throw new ArgumentNullException("key");
|
throw new ArgumentNullException("key");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var connection = CreateConnection(true).Result)
|
||||||
|
{
|
||||||
|
using (var cmd = connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = @key and userId=@userId";
|
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = @key and userId=@userId";
|
||||||
|
|
||||||
|
@ -301,6 +297,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public UserItemData GetUserData(Guid userId, List<string> keys)
|
public UserItemData GetUserData(Guid userId, List<string> keys)
|
||||||
{
|
{
|
||||||
|
@ -313,7 +310,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
throw new ArgumentNullException("keys");
|
throw new ArgumentNullException("keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var connection = CreateConnection(true).Result)
|
||||||
|
{
|
||||||
|
using (var cmd = connection.CreateCommand())
|
||||||
{
|
{
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var excludeIds = new List<string>();
|
var excludeIds = new List<string>();
|
||||||
|
@ -347,6 +346,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return all user-data associated with the given user
|
/// Return all user-data associated with the given user
|
||||||
|
@ -360,7 +360,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
throw new ArgumentNullException("userId");
|
throw new ArgumentNullException("userId");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
var list = new List<UserItemData>();
|
||||||
|
|
||||||
|
using (var connection = CreateConnection(true).Result)
|
||||||
|
{
|
||||||
|
using (var cmd = connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId";
|
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId";
|
||||||
|
|
||||||
|
@ -370,12 +374,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
yield return ReadRow(reader);
|
list.Add(ReadRow(reader));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read a row from the specified reader into the provided userData object
|
/// Read a row from the specified reader into the provided userData object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -414,19 +421,5 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CloseConnection()
|
|
||||||
{
|
|
||||||
if (_connection != null)
|
|
||||||
{
|
|
||||||
if (_connection.IsOpen())
|
|
||||||
{
|
|
||||||
_connection.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
_connection.Dispose();
|
|
||||||
_connection = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue