update connection pooling

This commit is contained in:
Luke Pulverenti 2016-06-11 16:12:01 -04:00
parent 96b1ddfddf
commit da6e94396f
17 changed files with 1587 additions and 1472 deletions

View File

@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.Chapters
/// <param name="chapters">The chapters.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task SaveChapters(string itemId, IEnumerable<ChapterInfo> chapters, CancellationToken cancellationToken);
Task SaveChapters(string itemId, List<ChapterInfo> chapters, CancellationToken cancellationToken);
/// <summary>
/// Searches the specified video.

View File

@ -81,7 +81,7 @@ namespace MediaBrowser.Controller.Persistence
/// <param name="chapters">The chapters.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task SaveChapters(Guid id, IEnumerable<ChapterInfo> chapters, CancellationToken cancellationToken);
Task SaveChapters(Guid id, List<ChapterInfo> chapters, CancellationToken cancellationToken);
/// <summary>
/// Gets the media streams.
@ -97,7 +97,7 @@ namespace MediaBrowser.Controller.Persistence
/// <param name="streams">The streams.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task SaveMediaStreams(Guid id, IEnumerable<MediaStream> streams, CancellationToken cancellationToken);
Task SaveMediaStreams(Guid id, List<MediaStream> streams, CancellationToken cancellationToken);
/// <summary>
/// Gets the item ids.

View File

@ -259,7 +259,7 @@ namespace MediaBrowser.Providers.Chapters
return _itemRepo.GetChapters(new Guid(itemId));
}
public Task SaveChapters(string itemId, IEnumerable<ChapterInfo> chapters, CancellationToken cancellationToken)
public Task SaveChapters(string itemId, List<ChapterInfo> chapters, CancellationToken cancellationToken)
{
return _itemRepo.SaveChapters(new Guid(itemId), chapters, cancellationToken);
}

View File

@ -30,12 +30,7 @@ namespace MediaBrowser.Server.Implementations.Activity
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 index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
"create index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)"
};
connection.RunQueries(queries, Logger);

View File

@ -1309,9 +1309,17 @@ namespace MediaBrowser.Server.Implementations.Library
AddUserToQuery(query, query.User);
}
if (query.EnableTotalRecordCount)
{
return ItemRepository.GetItems(query);
}
return new QueryResult<BaseItem>
{
Items = ItemRepository.GetItemList(query).ToArray()
};
}
public List<Guid> GetItemIds(InternalItemsQuery query)
{
if (query.User != null)

View File

@ -952,7 +952,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (query.Limit.HasValue)
{
internalQuery.Limit = Math.Max(query.Limit.Value * 5, 300);
internalQuery.Limit = Math.Max(query.Limit.Value * 5, 200);
}
if (query.HasAired.HasValue)

View File

@ -32,12 +32,7 @@ namespace MediaBrowser.Server.Implementations.Notifications
"create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT, Url TEXT, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT, PRIMARY KEY (Id, UserId))",
"create index if not exists idx_Notifications1 on Notifications(Id)",
"create index if not exists idx_Notifications2 on Notifications(UserId)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
"create index if not exists idx_Notifications2 on Notifications(UserId)"
};
connection.RunQueries(queries, Logger);

View File

@ -20,9 +20,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
Logger = logManager.GetLogger(GetType().Name);
}
protected Task<IDbConnection> CreateConnection(bool isReadOnly = false)
protected virtual async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
{
return DbConnector.Connect(DbFilePath, false, true);
var connection = await DbConnector.Connect(DbFilePath, false, true).ConfigureAwait(false);
connection.RunQueries(new []
{
"pragma temp_store = memory"
}, Logger);
return connection;
}
private bool _disposed;

View File

@ -53,12 +53,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
string[] queries = {
"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)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
"create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)"
};
connection.RunQueries(queries, Logger);

View File

@ -26,8 +26,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
throw new ArgumentNullException("dbPath");
}
logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, dbPath);
var connectionstr = new SQLiteConnectionStringBuilder
{
PageSize = 4096,
@ -39,7 +37,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
ReadOnly = isReadOnly
};
var connection = new SQLiteConnection(connectionstr.ConnectionString);
var connectionString = connectionstr.ConnectionString;
if (enablePooling)
{
connectionString += ";Max Pool Size=100";
}
//logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, connectionString);
var connection = new SQLiteConnection(connectionString);
await connection.OpenAsync().ConfigureAwait(false);

View File

@ -44,12 +44,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
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 index if not exists idx_FileOrganizerResults on FileOrganizerResults(ResultId)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
"create index if not exists idx_FileOrganizerResults on FileOrganizerResults(ResultId)"
};
_connection.RunQueries(queries, Logger);

View File

@ -45,12 +45,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
"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 index if not exists idx_userdata on userdata(key)",
"create unique index if not exists userdataindex on userdata (key, userId)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
"create unique index if not exists userdataindex on userdata (key, userId)"
};
connection.RunQueries(queries, Logger);

View File

@ -52,9 +52,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_users on users(guid)",
"create table if not exists schema_version (table_name primary key, version)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
};

View File

@ -32,12 +32,7 @@ namespace MediaBrowser.Server.Implementations.Security
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 index if not exists idx_AccessTokens on AccessTokens(Id)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
"create index if not exists idx_AccessTokens on AccessTokens(Id)"
};
connection.RunQueries(queries, Logger);

View File

@ -31,9 +31,6 @@ namespace MediaBrowser.Server.Implementations.Social
"create table if not exists Shares (Id GUID, ItemId TEXT, UserId TEXT, ExpirationDate DateTime, PRIMARY KEY (Id))",
"create index if not exists idx_Shares on Shares(Id)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
};

View File

@ -43,9 +43,6 @@ namespace MediaBrowser.Server.Implementations.Sync
"create index if not exists idx_SyncJobItems1 on SyncJobItems(Id)",
"create index if not exists idx_SyncJobItems2 on SyncJobItems(TargetId)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
};