rework connection management
This commit is contained in:
parent
92cf390fb0
commit
70df357e1e
|
@ -38,8 +38,6 @@ namespace Emby.Server.Implementations.Data
|
|||
/// </summary>
|
||||
public class SqliteItemRepository : BaseSqliteRepository, IItemRepository
|
||||
{
|
||||
private SQLiteDatabaseConnection _connection;
|
||||
|
||||
private readonly TypeMapper _typeMapper;
|
||||
|
||||
/// <summary>
|
||||
|
@ -97,13 +95,13 @@ namespace Emby.Server.Implementations.Data
|
|||
DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
|
||||
}
|
||||
|
||||
protected override bool AllowLockRecursion
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//protected override bool AllowLockRecursion
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
|
||||
private const string ChaptersTableName = "Chapters2";
|
||||
|
||||
|
@ -121,15 +119,27 @@ namespace Emby.Server.Implementations.Data
|
|||
}
|
||||
}
|
||||
|
||||
private SQLiteDatabaseConnection _backgroundConnection;
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
base.CloseConnection();
|
||||
|
||||
if (_backgroundConnection != null)
|
||||
{
|
||||
_backgroundConnection.Dispose();
|
||||
_backgroundConnection = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(SqliteUserDataRepository userDataRepo)
|
||||
{
|
||||
_connection = CreateConnection(false);
|
||||
|
||||
_connection.ExecuteAll(string.Join(";", new[]
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.ExecuteAll(string.Join(";", new[]
|
||||
{
|
||||
"PRAGMA page_size=4096",
|
||||
"PRAGMA default_temp_store=memory",
|
||||
|
@ -164,9 +174,9 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
};
|
||||
|
||||
_connection.RunQueries(queries);
|
||||
connection.RunQueries(queries);
|
||||
|
||||
_connection.RunInTransaction(db =>
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var existingColumnNames = GetColumnNames(db, "AncestorIds");
|
||||
AddColumn(db, "AncestorIds", "AncestorIdText", "Text", existingColumnNames);
|
||||
|
@ -350,13 +360,17 @@ namespace Emby.Server.Implementations.Data
|
|||
"create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)"
|
||||
};
|
||||
|
||||
_connection.RunQueries(postQueries);
|
||||
connection.RunQueries(postQueries);
|
||||
|
||||
//SqliteExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb");
|
||||
userDataRepo.Initialize(WriteLock);
|
||||
//await Vacuum(_connection).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
userDataRepo.Initialize(WriteLock);
|
||||
|
||||
_backgroundConnection = CreateConnection(true);
|
||||
}
|
||||
|
||||
private readonly string[] _retriveItemColumns =
|
||||
{
|
||||
"type",
|
||||
|
@ -2127,15 +2141,6 @@ namespace Emby.Server.Implementations.Data
|
|||
}
|
||||
}
|
||||
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
if (_connection != null)
|
||||
{
|
||||
_connection.Dispose();
|
||||
_connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
private bool EnableJoinUserData(InternalItemsQuery query)
|
||||
{
|
||||
if (query.User == null)
|
||||
|
|
Loading…
Reference in New Issue
Block a user