update connections
This commit is contained in:
parent
985c9111cf
commit
1dc080df8b
|
@ -27,6 +27,14 @@ namespace Emby.Server.Implementations.Activity
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY, Name TEXT, Overview TEXT, ShortOverview TEXT, Type TEXT, ItemId TEXT, UserId TEXT, DateCreated DATETIME, LogSeverity TEXT)",
|
"create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY, Name TEXT, Overview TEXT, ShortOverview TEXT, Type TEXT, ItemId TEXT, UserId TEXT, DateCreated DATETIME, LogSeverity TEXT)",
|
||||||
|
@ -51,9 +59,9 @@ namespace Emby.Server.Implementations.Activity
|
||||||
throw new ArgumentNullException("entry");
|
throw new ArgumentNullException("entry");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
@ -79,9 +87,9 @@ namespace Emby.Server.Implementations.Activity
|
||||||
|
|
||||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
||||||
{
|
{
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = BaseActivitySelectText;
|
var commandText = BaseActivitySelectText;
|
||||||
var whereClauses = new List<string>();
|
var whereClauses = new List<string>();
|
||||||
|
|
|
@ -30,11 +30,6 @@ namespace Emby.Server.Implementations.Data
|
||||||
get { return false; }
|
get { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool EnableConnectionPooling
|
|
||||||
{
|
|
||||||
get { return true; }
|
|
||||||
}
|
|
||||||
|
|
||||||
static BaseSqliteRepository()
|
static BaseSqliteRepository()
|
||||||
{
|
{
|
||||||
SQLite3.EnableSharedCache = false;
|
SQLite3.EnableSharedCache = false;
|
||||||
|
@ -45,7 +40,7 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
private static bool _versionLogged;
|
private static bool _versionLogged;
|
||||||
|
|
||||||
protected virtual SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false)
|
protected SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false, Action<SQLiteDatabaseConnection> onConnect = null)
|
||||||
{
|
{
|
||||||
if (!_versionLogged)
|
if (!_versionLogged)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +51,7 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
ConnectionFlags connectionFlags;
|
ConnectionFlags connectionFlags;
|
||||||
|
|
||||||
//isReadOnly = false;
|
isReadOnly = false;
|
||||||
|
|
||||||
if (isReadOnly)
|
if (isReadOnly)
|
||||||
{
|
{
|
||||||
|
@ -70,46 +65,40 @@ namespace Emby.Server.Implementations.Data
|
||||||
connectionFlags |= ConnectionFlags.ReadWrite;
|
connectionFlags |= ConnectionFlags.ReadWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EnableConnectionPooling)
|
connectionFlags |= ConnectionFlags.SharedCached;
|
||||||
{
|
|
||||||
connectionFlags |= ConnectionFlags.SharedCached;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
connectionFlags |= ConnectionFlags.PrivateCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
connectionFlags |= ConnectionFlags.NoMutex;
|
connectionFlags |= ConnectionFlags.NoMutex;
|
||||||
|
|
||||||
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
|
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
|
||||||
|
|
||||||
var queries = new List<string>
|
var queries = new List<string>
|
||||||
{
|
{
|
||||||
"pragma default_temp_store = memory",
|
"pragma temp_store = memory",
|
||||||
"PRAGMA page_size=4096",
|
"PRAGMA page_size=4096",
|
||||||
"PRAGMA journal_mode=WAL",
|
"PRAGMA journal_mode=WAL",
|
||||||
"PRAGMA temp_store=memory",
|
"pragma synchronous=Normal",
|
||||||
"PRAGMA synchronous=Normal",
|
|
||||||
//"PRAGMA cache size=-10000"
|
//"PRAGMA cache size=-10000"
|
||||||
};
|
};
|
||||||
|
|
||||||
var cacheSize = CacheSize;
|
//var cacheSize = CacheSize;
|
||||||
if (cacheSize.HasValue)
|
//if (cacheSize.HasValue)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EnableExclusiveMode)
|
|
||||||
{
|
|
||||||
queries.Add("PRAGMA locking_mode=EXCLUSIVE");
|
|
||||||
}
|
|
||||||
|
|
||||||
//foreach (var query in queries)
|
|
||||||
//{
|
//{
|
||||||
// db.Execute(query);
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
db.ExecuteAll(string.Join(";", queries.ToArray()));
|
////foreach (var query in queries)
|
||||||
|
////{
|
||||||
|
//// db.Execute(query);
|
||||||
|
////}
|
||||||
|
|
||||||
|
using (WriteLock.Write())
|
||||||
|
{
|
||||||
|
db.ExecuteAll(string.Join(";", queries.ToArray()));
|
||||||
|
|
||||||
|
if (onConnect != null)
|
||||||
|
{
|
||||||
|
onConnect(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
@ -122,11 +111,6 @@ namespace Emby.Server.Implementations.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool EnableExclusiveMode
|
|
||||||
{
|
|
||||||
get { return false; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void CheckOk(int rc)
|
internal static void CheckOk(int rc)
|
||||||
{
|
{
|
||||||
string msg = "";
|
string msg = "";
|
||||||
|
|
|
@ -54,9 +54,17 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists userdisplaypreferences (id GUID, userId GUID, client text, data BLOB)",
|
"create table if not exists userdisplaypreferences (id GUID, userId GUID, client text, data BLOB)",
|
||||||
"create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)"
|
"create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -86,9 +94,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
@ -130,9 +138,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
@ -162,9 +170,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
var guidId = displayPreferencesId.GetMD5();
|
var guidId = displayPreferencesId.GetMD5();
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"))
|
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"))
|
||||||
{
|
{
|
||||||
|
@ -196,9 +204,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
var list = new List<DisplayPreferences>();
|
var list = new List<DisplayPreferences>();
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId"))
|
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -131,11 +131,13 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
public static void Attach(IDatabaseConnection db, string path, string alias)
|
public static void Attach(IDatabaseConnection db, string path, string alias)
|
||||||
{
|
{
|
||||||
var commandText = string.Format("attach ? as {0};", alias);
|
var commandText = string.Format("attach @path as {0};", alias);
|
||||||
var paramList = new List<object>();
|
|
||||||
paramList.Add(path);
|
|
||||||
|
|
||||||
db.Execute(commandText, paramList.ToArray());
|
using (var statement = db.PrepareStatement(commandText))
|
||||||
|
{
|
||||||
|
statement.TryBind("@path", path);
|
||||||
|
statement.MoveNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsDBNull(this IReadOnlyList<IResultSetValue> result, int index)
|
public static bool IsDBNull(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
|
|
@ -31,6 +31,14 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists FileOrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, FileLength INT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",
|
"create table if not exists FileOrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, FileLength INT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,19 +14,12 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||||
{
|
{
|
||||||
private SQLiteDatabaseConnection _connection;
|
|
||||||
|
|
||||||
public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
|
public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool EnableConnectionPooling
|
|
||||||
{
|
|
||||||
get { return false; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the repository
|
/// Gets the name of the repository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -43,13 +36,24 @@ namespace Emby.Server.Implementations.Data
|
||||||
/// Opens the connection to the database
|
/// Opens the connection to the database
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
|
public void Initialize(ReaderWriterLockSlim writeLock)
|
||||||
{
|
{
|
||||||
WriteLock.Dispose();
|
WriteLock.Dispose();
|
||||||
WriteLock = writeLock;
|
WriteLock = writeLock;
|
||||||
_connection = connection;
|
|
||||||
|
|
||||||
string[] queries = {
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
|
string[] queries = {
|
||||||
|
|
||||||
|
"PRAGMA locking_mode=NORMAL",
|
||||||
|
|
||||||
"create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
"create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
||||||
|
|
||||||
|
@ -69,15 +73,16 @@ namespace Emby.Server.Implementations.Data
|
||||||
"pragma shrink_memory"
|
"pragma shrink_memory"
|
||||||
};
|
};
|
||||||
|
|
||||||
_connection.RunQueries(queries);
|
connection.RunQueries(queries);
|
||||||
|
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
var existingColumnNames = GetColumnNames(db, "userdata");
|
var existingColumnNames = GetColumnNames(db, "userdata");
|
||||||
|
|
||||||
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
|
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
|
||||||
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
|
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -139,18 +144,21 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
_connection.RunInTransaction(db =>
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
SaveUserData(db, userId, key, userData);
|
connection.RunInTransaction(db =>
|
||||||
});
|
{
|
||||||
|
SaveUserData(db, userId, key, userData);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
||||||
{
|
{
|
||||||
using (var statement = _connection.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
|
using (var statement = db.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
|
||||||
{
|
{
|
||||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
statement.TryBind("@Key", key);
|
statement.TryBind("@Key", key);
|
||||||
|
@ -207,15 +215,18 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
_connection.RunInTransaction(db =>
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
foreach (var userItemData in userDataList)
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
SaveUserData(db, userId, userItemData.Key, userItemData);
|
foreach (var userItemData in userDataList)
|
||||||
}
|
{
|
||||||
});
|
SaveUserData(db, userId, userItemData.Key, userItemData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,16 +252,19 @@ namespace Emby.Server.Implementations.Data
|
||||||
throw new ArgumentNullException("key");
|
throw new ArgumentNullException("key");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
|
||||||
statement.TryBind("@Key", key);
|
|
||||||
|
|
||||||
foreach (var row in statement.ExecuteQuery())
|
|
||||||
{
|
{
|
||||||
return ReadRow(row);
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
|
statement.TryBind("@Key", key);
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
|
{
|
||||||
|
return ReadRow(row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,15 +305,18 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
var list = new List<UserItemData>();
|
var list = new List<UserItemData>();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
|
||||||
|
|
||||||
foreach (var row in statement.ExecuteQuery())
|
|
||||||
{
|
{
|
||||||
list.Add(ReadRow(row));
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
|
{
|
||||||
|
list.Add(ReadRow(row));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,14 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists users (guid GUID primary key, data BLOB)",
|
"create table if not exists users (guid GUID primary key, data BLOB)",
|
||||||
|
@ -83,9 +91,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
@ -108,9 +116,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
var list = new List<User>();
|
var list = new List<User>();
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
foreach (var row in connection.Query("select guid,data from users"))
|
foreach (var row in connection.Query("select guid,data from users"))
|
||||||
{
|
{
|
||||||
|
@ -146,9 +154,9 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,16 @@ namespace Emby.Server.Implementations.Notifications
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT NULL, Url TEXT NULL, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT NULL, PRIMARY KEY (Id, UserId))",
|
"create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT NULL, Url TEXT NULL, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT NULL, PRIMARY KEY (Id, UserId))",
|
||||||
"create index if not exists idx_Notifications1 on Notifications(Id)",
|
"create index if not exists idx_Notifications1 on Notifications(Id)",
|
||||||
"create index if not exists idx_Notifications2 on Notifications(UserId)"
|
"create index if not exists idx_Notifications2 on Notifications(UserId)"
|
||||||
|
@ -103,9 +112,9 @@ namespace Emby.Server.Implementations.Notifications
|
||||||
{
|
{
|
||||||
var result = new NotificationsSummary();
|
var result = new NotificationsSummary();
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead"))
|
using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead"))
|
||||||
{
|
{
|
||||||
|
@ -220,9 +229,9 @@ namespace Emby.Server.Implementations.Notifications
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
|
@ -283,9 +292,9 @@ namespace Emby.Server.Implementations.Notifications
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
|
@ -305,9 +314,9 @@ namespace Emby.Server.Implementations.Notifications
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,9 +30,17 @@ namespace Emby.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists AccessTokens (Id GUID PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT, AppName TEXT, AppVersion TEXT, DeviceName TEXT, UserId TEXT, IsActive BIT, DateCreated DATETIME NOT NULL, DateRevoked DATETIME)",
|
"create table if not exists AccessTokens (Id GUID PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT, AppName TEXT, AppVersion TEXT, DeviceName TEXT, UserId TEXT, IsActive BIT, DateCreated DATETIME NOT NULL, DateRevoked DATETIME)",
|
||||||
"create index if not exists idx_AccessTokens on AccessTokens(Id)"
|
"create index if not exists idx_AccessTokens on AccessTokens(Id)"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,9 +71,9 @@ namespace Emby.Server.Implementations.Security
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
@ -200,28 +208,31 @@ namespace Emby.Server.Implementations.Security
|
||||||
|
|
||||||
var list = new List<AuthenticationInfo>();
|
var list = new List<AuthenticationInfo>();
|
||||||
|
|
||||||
using (var statement = connection.PrepareStatement(commandText))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
BindAuthenticationQueryParams(query, statement);
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
|
|
||||||
foreach (var row in statement.ExecuteQuery())
|
|
||||||
{
|
{
|
||||||
list.Add(Get(row));
|
BindAuthenticationQueryParams(query, statement);
|
||||||
}
|
|
||||||
|
|
||||||
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
|
||||||
BindAuthenticationQueryParams(query, totalCountStatement);
|
|
||||||
|
|
||||||
var count = totalCountStatement.ExecuteQuery()
|
|
||||||
.SelectScalarInt()
|
|
||||||
.First();
|
|
||||||
|
|
||||||
return new QueryResult<AuthenticationInfo>()
|
|
||||||
{
|
{
|
||||||
Items = list.ToArray(),
|
list.Add(Get(row));
|
||||||
TotalRecordCount = count
|
}
|
||||||
};
|
|
||||||
|
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
|
||||||
|
{
|
||||||
|
BindAuthenticationQueryParams(query, totalCountStatement);
|
||||||
|
|
||||||
|
var count = totalCountStatement.ExecuteQuery()
|
||||||
|
.SelectScalarInt()
|
||||||
|
.First();
|
||||||
|
|
||||||
|
return new QueryResult<AuthenticationInfo>()
|
||||||
|
{
|
||||||
|
Items = list.ToArray(),
|
||||||
|
TotalRecordCount = count
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,9 +245,9 @@ namespace Emby.Server.Implementations.Security
|
||||||
throw new ArgumentNullException("id");
|
throw new ArgumentNullException("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = BaseSelectText + " where Id=@Id";
|
var commandText = BaseSelectText + " where Id=@Id";
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,14 @@ namespace Emby.Server.Implementations.Social
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists Shares (Id GUID, ItemId TEXT, UserId TEXT, ExpirationDate DateTime, PRIMARY KEY (Id))",
|
"create table if not exists Shares (Id GUID, ItemId TEXT, UserId TEXT, ExpirationDate DateTime, PRIMARY KEY (Id))",
|
||||||
|
@ -50,9 +58,9 @@ namespace Emby.Server.Implementations.Social
|
||||||
throw new ArgumentNullException("info.Id");
|
throw new ArgumentNullException("info.Id");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
|
@ -75,9 +83,9 @@ namespace Emby.Server.Implementations.Social
|
||||||
throw new ArgumentNullException("id");
|
throw new ArgumentNullException("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = "select Id, ItemId, UserId, ExpirationDate from Shares where id = ?";
|
var commandText = "select Id, ItemId, UserId, ExpirationDate from Shares where id = ?";
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,14 @@ namespace Emby.Server.Implementations.Sync
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
|
connection.ExecuteAll(string.Join(";", new[]
|
||||||
|
{
|
||||||
|
"pragma default_temp_store = memory",
|
||||||
|
"pragma default_synchronous=Normal",
|
||||||
|
"pragma temp_store = memory",
|
||||||
|
"pragma synchronous=Normal",
|
||||||
|
}));
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
|
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
|
||||||
|
@ -95,9 +103,9 @@ namespace Emby.Server.Implementations.Sync
|
||||||
throw new ArgumentNullException("id");
|
throw new ArgumentNullException("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = BaseJobSelectText + " where Id=?";
|
var commandText = BaseJobSelectText + " where Id=?";
|
||||||
var paramList = new List<object>();
|
var paramList = new List<object>();
|
||||||
|
@ -206,9 +214,9 @@ namespace Emby.Server.Implementations.Sync
|
||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
string commandText;
|
string commandText;
|
||||||
var paramList = new List<object>();
|
var paramList = new List<object>();
|
||||||
|
@ -259,9 +267,9 @@ namespace Emby.Server.Implementations.Sync
|
||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
|
@ -281,9 +289,9 @@ namespace Emby.Server.Implementations.Sync
|
||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = BaseJobSelectText;
|
var commandText = BaseJobSelectText;
|
||||||
var paramList = new List<object>();
|
var paramList = new List<object>();
|
||||||
|
@ -379,11 +387,11 @@ namespace Emby.Server.Implementations.Sync
|
||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
using (WriteLock.Read())
|
var guid = new Guid(id);
|
||||||
{
|
|
||||||
var guid = new Guid(id);
|
|
||||||
|
|
||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
|
{
|
||||||
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = BaseJobItemSelectText + " where Id=?";
|
var commandText = BaseJobItemSelectText + " where Id=?";
|
||||||
var paramList = new List<object>();
|
var paramList = new List<object>();
|
||||||
|
@ -407,9 +415,9 @@ namespace Emby.Server.Implementations.Sync
|
||||||
throw new ArgumentNullException("query");
|
throw new ArgumentNullException("query");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (WriteLock.Read())
|
||||||
{
|
{
|
||||||
var commandText = baseSelectText;
|
var commandText = baseSelectText;
|
||||||
var paramList = new List<object>();
|
var paramList = new List<object>();
|
||||||
|
@ -487,30 +495,30 @@ namespace Emby.Server.Implementations.Sync
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
|
|
||||||
using (WriteLock.Read())
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
var commandText = "select ItemId,Status,Progress from SyncJobItems";
|
||||||
|
var whereClauses = new List<string>();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||||
{
|
{
|
||||||
var commandText = "select ItemId,Status,Progress from SyncJobItems";
|
whereClauses.Add("TargetId=@TargetId");
|
||||||
var whereClauses = new List<string>();
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
if (query.Statuses.Length > 0)
|
||||||
{
|
{
|
||||||
whereClauses.Add("TargetId=@TargetId");
|
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||||
}
|
|
||||||
|
|
||||||
if (query.Statuses.Length > 0)
|
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||||
{
|
}
|
||||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
|
||||||
|
|
||||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
if (whereClauses.Count > 0)
|
||||||
}
|
{
|
||||||
|
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||||
if (whereClauses.Count > 0)
|
}
|
||||||
{
|
|
||||||
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
using (WriteLock.Read())
|
||||||
|
{
|
||||||
using (var statement = connection.PrepareStatement(commandText))
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||||
|
@ -664,9 +672,9 @@ namespace Emby.Server.Implementations.Sync
|
||||||
|
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
using (WriteLock.Write())
|
using (var connection = CreateConnection())
|
||||||
{
|
{
|
||||||
using (var connection = CreateConnection())
|
using (WriteLock.Write())
|
||||||
{
|
{
|
||||||
string commandText;
|
string commandText;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user