@ -78,8 +78,8 @@ namespace MediaBrowser.Server.Implementations.Sqlite
string [ ] queries = {
string [ ] queries = {
"create table if not exists displaypreferences (id GUID, userId GUID, data BLOB)",
"create table if not exists displaypreferences (id GUID, data BLOB)",
"create unique index if not exists displaypreferencesindex on displaypreferences (id , userId )",
"create unique index if not exists displaypreferencesindex on displaypreferences (id )",
"create table if not exists schema_version (table_name primary key, version)" ,
"create table if not exists schema_version (table_name primary key, version)" ,
//pragmas
//pragmas
"pragma temp_store = memory"
"pragma temp_store = memory"
@ -91,29 +91,23 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <summary>
/// <summary>
/// Save the display preferences associated with an item in the repo
/// Save the display preferences associated with an item in the repo
/// </summary>
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="displayPreferencesId">The display preferences id.</param>
/// <param name="displayPreferences">The display preferences.</param>
/// <param name="displayPreferences">The display preferences.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
/// <exception cref="System.ArgumentNullException">item</exception>
public Task SaveDisplayPreferences ( Guid userId , Guid displayPreferencesId , DisplayPreferences displayPreferences , CancellationToken cancellationToken )
public Task SaveDisplayPreferences ( DisplayPreferences displayPreferences , CancellationToken cancellationToken )
{
{
if ( displayPreferences = = null )
if ( displayPreferences = = null )
{
{
throw new ArgumentNullException ( "displayPreferences" ) ;
throw new ArgumentNullException ( "displayPreferences" ) ;
}
}
if ( cancellationToken = = null )
if ( displayPreferences . Id = = Guid . Empty )
{
throw new ArgumentNullException ( "cancellationToken" ) ;
}
if ( userId = = Guid . Empty )
{
{
throw new ArgumentNullException ( " user Id") ;
throw new ArgumentNullException ( "displayPreferences.Id" ) ;
}
}
if ( displayPreferencesId = = Guid . Empty )
if ( cancellationToken = = null )
{
{
throw new ArgumentNullException ( " displayPreferencesId ") ;
throw new ArgumentNullException ( " cancellationToken ") ;
}
}
cancellationToken . ThrowIfCancellationRequested ( ) ;
cancellationToken . ThrowIfCancellationRequested ( ) ;
@ -125,10 +119,9 @@ namespace MediaBrowser.Server.Implementations.Sqlite
cancellationToken . ThrowIfCancellationRequested ( ) ;
cancellationToken . ThrowIfCancellationRequested ( ) ;
var cmd = connection . CreateCommand ( ) ;
var cmd = connection . CreateCommand ( ) ;
cmd . CommandText = "replace into displaypreferences (id, userId, data) values (@1, @2, @3)" ;
cmd . CommandText = "replace into displaypreferences (id, data) values (@1, @3)" ;
cmd . AddParam ( "@1" , displayPreferencesId ) ;
cmd . AddParam ( "@1" , displayPreferences . Id ) ;
cmd . AddParam ( "@2" , userId ) ;
cmd . AddParam ( "@2" , serialized ) ;
cmd . AddParam ( "@3" , serialized ) ;
QueueCommand ( cmd ) ;
QueueCommand ( cmd ) ;
} ) ;
} ) ;
}
}
@ -136,30 +129,22 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <summary>
/// <summary>
/// Gets the display preferences.
/// Gets the display preferences.
/// </summary>
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="displayPreferencesId">The display preferences id.</param>
/// <param name="displayPreferencesId">The display preferences id.</param>
/// <returns>Task{DisplayPreferences}.</returns>
/// <returns>Task{DisplayPreferences}.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
/// <exception cref="System.ArgumentNullException">item</exception>
public async Task < DisplayPreferences > GetDisplayPreferences ( Guid userId, Guid displayPreferencesId)
public async Task < DisplayPreferences > GetDisplayPreferences ( Guid displayPreferencesId)
{
{
if ( userId = = Guid . Empty )
{
throw new ArgumentNullException ( "userId" ) ;
}
if ( displayPreferencesId = = Guid . Empty )
if ( displayPreferencesId = = Guid . Empty )
{
{
throw new ArgumentNullException ( "displayPreferencesId" ) ;
throw new ArgumentNullException ( "displayPreferencesId" ) ;
}
}
var cmd = connection . CreateCommand ( ) ;
var cmd = connection . CreateCommand ( ) ;
cmd . CommandText = "select data from displaypreferences where id = @id and userId=@userId ";
cmd . CommandText = "select data from displaypreferences where id = @id ";
var idParam = cmd . Parameters . Add ( "@id" , DbType . Guid ) ;
var idParam = cmd . Parameters . Add ( "@id" , DbType . Guid ) ;
idParam . Value = displayPreferencesId ;
idParam . Value = displayPreferencesId ;
var userIdParam = cmd . Parameters . Add ( "@userId" , DbType . Guid ) ;
userIdParam . Value = userId ;
using ( var reader = await cmd . ExecuteReaderAsync ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult | CommandBehavior . SingleRow ) . ConfigureAwait ( false ) )
using ( var reader = await cmd . ExecuteReaderAsync ( CommandBehavior . SequentialAccess | CommandBehavior . SingleResult | CommandBehavior . SingleRow ) . ConfigureAwait ( false ) )
{
{
if ( reader . Read ( ) )
if ( reader . Read ( ) )