mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 13:57:14 -04:00
commit
f838ae0a46
@ -114,7 +114,7 @@ namespace MediaBrowser.Api
|
||||
config.EnableStandaloneMusicKeys = true;
|
||||
config.EnableCaseSensitiveItemIds = true;
|
||||
config.EnableFolderView = true;
|
||||
config.SchemaVersion = 89;
|
||||
config.SchemaVersion = 91;
|
||||
}
|
||||
|
||||
public void Post(UpdateStartupConfiguration request)
|
||||
|
@ -53,6 +53,8 @@ namespace MediaBrowser.Controller.Channels
|
||||
|
||||
public bool IsInfiniteStream { get; set; }
|
||||
|
||||
public string HomePageUrl { get; set; }
|
||||
|
||||
public ChannelItemInfo()
|
||||
{
|
||||
MediaSources = new List<ChannelMediaInfo>();
|
||||
|
@ -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.
|
||||
|
@ -71,6 +71,9 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
public List<ItemImageInfo> ImageInfos { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsVirtualItem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the album.
|
||||
/// </summary>
|
||||
|
@ -117,6 +117,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
public bool? IsCurrentSchema { get; set; }
|
||||
public bool? HasDeadParentId { get; set; }
|
||||
public bool? IsOffline { get; set; }
|
||||
public bool? IsVirtualItem { get; set; }
|
||||
|
||||
public Guid? ParentId { get; set; }
|
||||
public string[] AncestorIds { get; set; }
|
||||
|
@ -128,39 +128,16 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
return IndexNumber != null ? IndexNumber.Value.ToString("0000") : Name;
|
||||
}
|
||||
|
||||
public override bool RequiresRefresh()
|
||||
{
|
||||
var result = base.RequiresRefresh();
|
||||
|
||||
if (!result)
|
||||
{
|
||||
if (!IsVirtualItem.HasValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool? IsVirtualItem { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsMissingSeason
|
||||
{
|
||||
get { return (IsVirtualItem ?? DetectIsVirtualItem()) && !IsUnaired; }
|
||||
get { return (IsVirtualItem) && !IsUnaired; }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsVirtualUnaired
|
||||
{
|
||||
get { return (IsVirtualItem ?? DetectIsVirtualItem()) && IsUnaired; }
|
||||
}
|
||||
|
||||
private bool DetectIsVirtualItem()
|
||||
{
|
||||
return LocationType == LocationType.Virtual && GetEpisodes().All(i => i.LocationType == LocationType.Virtual);
|
||||
get { return (IsVirtualItem) && IsUnaired; }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
|
@ -92,10 +92,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetRecursiveChildren(i => i is Episode)
|
||||
.Select(i => i.DateCreated)
|
||||
.OrderByDescending(i => i)
|
||||
.FirstOrDefault();
|
||||
return DateLastMediaAdded ?? DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,6 +237,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
AncestorWithPresentationUniqueKey = PresentationUniqueKey,
|
||||
IncludeItemTypes = new[] { typeof(Episode).Name, typeof(Season).Name },
|
||||
SortBy = new[] { ItemSortBy.SortName }
|
||||
|
||||
}).ToList();
|
||||
|
||||
var allSeriesEpisodes = allItems.OfType<Episode>().ToList();
|
||||
|
@ -665,6 +665,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
query.SetUser(user);
|
||||
query.Limit = GetSpecialItemsLimit();
|
||||
query.IncludeItemTypes = new[] { typeof(Episode).Name };
|
||||
query.ExcludeLocationTypes = new[] { LocationType.Virtual };
|
||||
|
||||
return _libraryManager.GetItemsResult(query);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -428,7 +428,8 @@ namespace MediaBrowser.Providers.TV
|
||||
Name = name,
|
||||
IndexNumber = episodeNumber,
|
||||
ParentIndexNumber = seasonNumber,
|
||||
Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode))
|
||||
Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)),
|
||||
IsVirtualItem = true
|
||||
};
|
||||
|
||||
episode.SetParent(season);
|
||||
|
@ -195,28 +195,35 @@ namespace MediaBrowser.Providers.TV
|
||||
|
||||
private async void LibraryUpdateTimerCallback(object state)
|
||||
{
|
||||
if (MissingEpisodeProvider.IsRunning)
|
||||
try
|
||||
{
|
||||
return;
|
||||
if (MissingEpisodeProvider.IsRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_libraryManager.IsScanRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var seriesList = _libraryManager.GetItemList(new InternalItemsQuery()
|
||||
{
|
||||
IncludeItemTypes = new[] { typeof(Series).Name },
|
||||
Recursive = true,
|
||||
GroupByPresentationUniqueKey = false
|
||||
|
||||
}).Cast<Series>().ToList();
|
||||
|
||||
var seriesGroups = SeriesPostScanTask.FindSeriesGroups(seriesList).Where(g => !string.IsNullOrEmpty(g.Key)).ToList();
|
||||
|
||||
await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem)
|
||||
.Run(seriesGroups, false, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (_libraryManager.IsScanRunning)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ;
|
||||
_logger.ErrorException("Error in SeriesPostScanTask", ex);
|
||||
}
|
||||
|
||||
var seriesList = _libraryManager.GetItemList(new InternalItemsQuery()
|
||||
{
|
||||
IncludeItemTypes = new[] { typeof(Series).Name },
|
||||
Recursive = true,
|
||||
GroupByPresentationUniqueKey = false
|
||||
|
||||
}).Cast<Series>().ToList();
|
||||
|
||||
var seriesGroups = SeriesPostScanTask.FindSeriesGroups(seriesList).Where(g => !string.IsNullOrEmpty(g.Key)).ToList();
|
||||
|
||||
await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem)
|
||||
.Run(seriesGroups, false, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private bool FilterItem(BaseItem item)
|
||||
|
@ -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);
|
||||
|
@ -1307,6 +1307,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
item.OfficialRating = info.OfficialRating;
|
||||
item.DateCreated = info.DateCreated ?? DateTime.UtcNow;
|
||||
item.Tags = info.Tags;
|
||||
item.HomePageUrl = info.HomePageUrl;
|
||||
}
|
||||
|
||||
var trailer = item as Trailer;
|
||||
|
@ -1309,7 +1309,15 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
AddUserToQuery(query, query.User);
|
||||
}
|
||||
|
||||
return ItemRepository.GetItems(query);
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
return ItemRepository.GetItems(query);
|
||||
}
|
||||
|
||||
return new QueryResult<BaseItem>
|
||||
{
|
||||
Items = ItemRepository.GetItemList(query).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
public List<Guid> GetItemIds(InternalItemsQuery query)
|
||||
|
@ -202,23 +202,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
var includeTypes = request.IncludeItemTypes;
|
||||
|
||||
var currentUser = user;
|
||||
|
||||
var libraryItems = GetItemsForLatestItems(user, request.ParentId, includeTypes, request.Limit ?? 10).Where(i =>
|
||||
{
|
||||
if (request.IsPlayed.HasValue)
|
||||
{
|
||||
var val = request.IsPlayed.Value;
|
||||
if (i is Video && i.IsPlayed(currentUser) != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
var libraryItems = GetItemsForLatestItems(user, request);
|
||||
|
||||
var list = new List<Tuple<BaseItem, List<BaseItem>>>();
|
||||
|
||||
@ -254,8 +238,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
return list;
|
||||
}
|
||||
|
||||
private IEnumerable<BaseItem> GetItemsForLatestItems(User user, string parentId, string[] includeItemTypes, int limit)
|
||||
private IEnumerable<BaseItem> GetItemsForLatestItems(User user, LatestItemsQuery request)
|
||||
{
|
||||
var parentId = request.ParentId;
|
||||
|
||||
var includeItemTypes = request.IncludeItemTypes;
|
||||
var limit = request.Limit ?? 10;
|
||||
|
||||
var parentIds = string.IsNullOrEmpty(parentId)
|
||||
? new string[] { }
|
||||
: new[] { parentId };
|
||||
@ -276,7 +265,12 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
|
||||
var excludeItemTypes = includeItemTypes.Length == 0 ? new[]
|
||||
{
|
||||
typeof(Person).Name, typeof(Studio).Name, typeof(Year).Name, typeof(GameGenre).Name, typeof(MusicGenre).Name, typeof(Genre).Name
|
||||
typeof(Person).Name,
|
||||
typeof(Studio).Name,
|
||||
typeof(Year).Name,
|
||||
typeof(GameGenre).Name,
|
||||
typeof(MusicGenre).Name,
|
||||
typeof(Genre).Name
|
||||
|
||||
} : new string[] { };
|
||||
|
||||
@ -288,8 +282,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
IsFolder = includeItemTypes.Length == 0 ? false : (bool?)null,
|
||||
ExcludeItemTypes = excludeItemTypes,
|
||||
ExcludeLocationTypes = new[] { LocationType.Virtual },
|
||||
Limit = limit * 20,
|
||||
ExcludeSourceTypes = parentIds.Length == 0 ? new[] { SourceType.Channel, SourceType.LiveTV } : new SourceType[] { }
|
||||
Limit = limit * 5,
|
||||
ExcludeSourceTypes = parentIds.Length == 0 ? new[] { SourceType.Channel, SourceType.LiveTV } : new SourceType[] { },
|
||||
IsPlayed = request.IsPlayed
|
||||
|
||||
}, parentIds);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
||||
var streams = mediaSource.MediaStreams ?? new List<MediaStream>();
|
||||
if (streams.Any(i => i.Type == MediaStreamType.Audio && (i.Codec ?? string.Empty).IndexOf("aac", StringComparison.OrdinalIgnoreCase) != -1))
|
||||
{
|
||||
return Path.ChangeExtension(targetFile, ".mkv");
|
||||
return Path.ChangeExtension(targetFile, ".ts");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 * 4, 200);
|
||||
}
|
||||
|
||||
if (query.HasAired.HasValue)
|
||||
|
@ -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);
|
||||
|
@ -20,9 +20,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
Logger = logManager.GetLogger(GetType().Name);
|
||||
}
|
||||
|
||||
protected Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
protected virtual bool EnableConnectionPooling
|
||||
{
|
||||
return DbConnector.Connect(DbFilePath, false, true);
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
protected virtual async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
var connection = await DbConnector.Connect(DbFilePath, false, true).ConfigureAwait(false);
|
||||
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"pragma temp_store = memory"
|
||||
|
||||
}, Logger);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
private bool _disposed;
|
||||
@ -95,7 +108,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
protected virtual void CloseConnection()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
ReadOnly = isReadOnly
|
||||
};
|
||||
|
||||
var connection = new SQLiteConnection(connectionstr.ConnectionString);
|
||||
var connectionString = connectionstr.ConnectionString;
|
||||
|
||||
//logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, connectionString);
|
||||
SQLiteConnection.SetMemoryStatus(false);
|
||||
|
||||
var connection = new SQLiteConnection(connectionString);
|
||||
|
||||
await connection.OpenAsync().ConfigureAwait(false);
|
||||
|
||||
|
@ -16,74 +16,29 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
{
|
||||
public class SqliteFileOrganizationRepository : BaseSqliteRepository, IFileOrganizationRepository, IDisposable
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
|
||||
private readonly IServerApplicationPaths _appPaths;
|
||||
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
|
||||
private IDbCommand _saveResultCommand;
|
||||
private IDbCommand _deleteResultCommand;
|
||||
private IDbCommand _deleteAllCommand;
|
||||
|
||||
public SqliteFileOrganizationRepository(ILogManager logManager, IServerApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
||||
{
|
||||
_appPaths = appPaths;
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "fileorganization.db");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(IDbConnector dbConnector)
|
||||
public async Task Initialize()
|
||||
{
|
||||
var dbFile = Path.Combine(_appPaths.DataPath, "fileorganization.db");
|
||||
|
||||
_connection = await dbConnector.Connect(dbFile, false).ConfigureAwait(false);
|
||||
|
||||
string[] queries = {
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
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);
|
||||
|
||||
PrepareStatements();
|
||||
}
|
||||
|
||||
private void PrepareStatements()
|
||||
{
|
||||
_saveResultCommand = _connection.CreateCommand();
|
||||
_saveResultCommand.CommandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (@ResultId, @OriginalPath, @TargetPath, @FileLength, @OrganizationDate, @Status, @OrganizationType, @StatusMessage, @ExtractedName, @ExtractedYear, @ExtractedSeasonNumber, @ExtractedEpisodeNumber, @ExtractedEndingEpisodeNumber, @DuplicatePaths)";
|
||||
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OriginalPath");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@TargetPath");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@FileLength");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationDate");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@Status");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationType");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@StatusMessage");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ExtractedName");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ExtractedYear");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ExtractedSeasonNumber");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ExtractedEpisodeNumber");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ExtractedEndingEpisodeNumber");
|
||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@DuplicatePaths");
|
||||
|
||||
_deleteResultCommand = _connection.CreateCommand();
|
||||
_deleteResultCommand.CommandText = "delete from FileOrganizerResults where ResultId = @ResultId";
|
||||
|
||||
_deleteResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
|
||||
|
||||
_deleteAllCommand = _connection.CreateCommand();
|
||||
_deleteAllCommand.CommandText = "delete from FileOrganizerResults";
|
||||
connection.RunQueries(queries, Logger);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
|
||||
@ -95,65 +50,84 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
transaction = _connection.BeginTransaction();
|
||||
|
||||
var index = 0;
|
||||
|
||||
_saveResultCommand.GetParameter(index++).Value = new Guid(result.Id);
|
||||
_saveResultCommand.GetParameter(index++).Value = result.OriginalPath;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.TargetPath;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.FileSize;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.Date;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.Status.ToString();
|
||||
_saveResultCommand.GetParameter(index++).Value = result.Type.ToString();
|
||||
_saveResultCommand.GetParameter(index++).Value = result.StatusMessage;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.ExtractedName;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.ExtractedYear;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.ExtractedSeasonNumber;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.ExtractedEpisodeNumber;
|
||||
_saveResultCommand.GetParameter(index++).Value = result.ExtractedEndingEpisodeNumber;
|
||||
_saveResultCommand.GetParameter(index).Value = string.Join("|", result.DuplicatePaths.ToArray());
|
||||
|
||||
_saveResultCommand.Transaction = transaction;
|
||||
|
||||
_saveResultCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
using (var saveResultCommand = connection.CreateCommand())
|
||||
{
|
||||
transaction.Rollback();
|
||||
saveResultCommand.CommandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (@ResultId, @OriginalPath, @TargetPath, @FileLength, @OrganizationDate, @Status, @OrganizationType, @StatusMessage, @ExtractedName, @ExtractedYear, @ExtractedSeasonNumber, @ExtractedEpisodeNumber, @ExtractedEndingEpisodeNumber, @DuplicatePaths)";
|
||||
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ResultId");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@OriginalPath");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@TargetPath");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@FileLength");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@OrganizationDate");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@Status");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@OrganizationType");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@StatusMessage");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedName");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedYear");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedSeasonNumber");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedEpisodeNumber");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedEndingEpisodeNumber");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@DuplicatePaths");
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var index = 0;
|
||||
|
||||
saveResultCommand.GetParameter(index++).Value = new Guid(result.Id);
|
||||
saveResultCommand.GetParameter(index++).Value = result.OriginalPath;
|
||||
saveResultCommand.GetParameter(index++).Value = result.TargetPath;
|
||||
saveResultCommand.GetParameter(index++).Value = result.FileSize;
|
||||
saveResultCommand.GetParameter(index++).Value = result.Date;
|
||||
saveResultCommand.GetParameter(index++).Value = result.Status.ToString();
|
||||
saveResultCommand.GetParameter(index++).Value = result.Type.ToString();
|
||||
saveResultCommand.GetParameter(index++).Value = result.StatusMessage;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedName;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedYear;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedSeasonNumber;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedEpisodeNumber;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedEndingEpisodeNumber;
|
||||
saveResultCommand.GetParameter(index).Value = string.Join("|", result.DuplicatePaths.ToArray());
|
||||
|
||||
saveResultCommand.Transaction = transaction;
|
||||
|
||||
saveResultCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save FileOrganizationResult:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save FileOrganizationResult:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,100 +138,110 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
transaction = _connection.BeginTransaction();
|
||||
|
||||
_deleteResultCommand.GetParameter(0).Value = new Guid(id);
|
||||
|
||||
_deleteResultCommand.Transaction = transaction;
|
||||
|
||||
_deleteResultCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
using (var deleteResultCommand = connection.CreateCommand())
|
||||
{
|
||||
transaction.Rollback();
|
||||
deleteResultCommand.CommandText = "delete from FileOrganizerResults where ResultId = @ResultId";
|
||||
|
||||
deleteResultCommand.Parameters.Add(deleteResultCommand, "@ResultId");
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
deleteResultCommand.GetParameter(0).Value = new Guid(id);
|
||||
|
||||
deleteResultCommand.Transaction = transaction;
|
||||
|
||||
deleteResultCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete FileOrganizationResult:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete FileOrganizationResult:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAll()
|
||||
{
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
transaction = _connection.BeginTransaction();
|
||||
|
||||
_deleteAllCommand.Transaction = transaction;
|
||||
|
||||
_deleteAllCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
transaction.Rollback();
|
||||
cmd.CommandText = "delete from FileOrganizerResults";
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete results", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete results", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
@ -265,46 +249,49 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
cmd.CommandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults";
|
||||
|
||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText += string.Format(" WHERE ResultId NOT IN (SELECT ResultId FROM FileOrganizerResults ORDER BY OrganizationDate desc LIMIT {0})",
|
||||
query.StartIndex.Value.ToString(_usCulture));
|
||||
}
|
||||
cmd.CommandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults";
|
||||
|
||||
cmd.CommandText += " ORDER BY OrganizationDate desc";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
cmd.CommandText += "; select count (ResultId) from FileOrganizerResults";
|
||||
|
||||
var list = new List<FileOrganizationResult>();
|
||||
var count = 0;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||
{
|
||||
while (reader.Read())
|
||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||
{
|
||||
list.Add(GetResult(reader));
|
||||
cmd.CommandText += string.Format(" WHERE ResultId NOT IN (SELECT ResultId FROM FileOrganizerResults ORDER BY OrganizationDate desc LIMIT {0})",
|
||||
query.StartIndex.Value.ToString(_usCulture));
|
||||
}
|
||||
|
||||
if (reader.NextResult() && reader.Read())
|
||||
{
|
||||
count = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
cmd.CommandText += " ORDER BY OrganizationDate desc";
|
||||
|
||||
return new QueryResult<FileOrganizationResult>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
cmd.CommandText += "; select count (ResultId) from FileOrganizerResults";
|
||||
|
||||
var list = new List<FileOrganizationResult>();
|
||||
var count = 0;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(GetResult(reader));
|
||||
}
|
||||
|
||||
if (reader.NextResult() && reader.Read())
|
||||
{
|
||||
count = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryResult<FileOrganizationResult>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,24 +302,27 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
var guid = new Guid(id);
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
cmd.CommandText = "select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=@Id";
|
||||
var guid = new Guid(id);
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
if (reader.Read())
|
||||
cmd.CommandText = "select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=@Id";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
{
|
||||
return GetResult(reader);
|
||||
if (reader.Read())
|
||||
{
|
||||
return GetResult(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public FileOrganizationResult GetResult(IDataReader reader)
|
||||
@ -414,19 +404,5 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
if (_connection != null)
|
||||
{
|
||||
if (_connection.IsOpen())
|
||||
{
|
||||
_connection.Close();
|
||||
}
|
||||
|
||||
_connection.Dispose();
|
||||
_connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,19 +115,31 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
_jsonSerializer = jsonSerializer;
|
||||
|
||||
_criticReviewsPath = Path.Combine(_config.ApplicationPaths.DataPath, "critic-reviews");
|
||||
DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
|
||||
}
|
||||
|
||||
private const string ChaptersTableName = "Chapters2";
|
||||
|
||||
protected override async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
var connection = await DbConnector.Connect(DbFilePath, false, false, 6000).ConfigureAwait(false);
|
||||
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"pragma temp_store = memory"
|
||||
|
||||
}, Logger);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(IDbConnector dbConnector)
|
||||
public async Task Initialize()
|
||||
{
|
||||
var dbFile = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
|
||||
|
||||
_connection = await dbConnector.Connect(dbFile, false, false, 6000).ConfigureAwait(false);
|
||||
_connection = await CreateConnection(false).ConfigureAwait(false);
|
||||
|
||||
var createMediaStreamsTableCommand
|
||||
= "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
|
||||
@ -137,7 +149,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
"create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID, Path TEXT)",
|
||||
"create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)",
|
||||
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
|
||||
"create index if not exists idx_TypedBaseItems2 on TypedBaseItems(Type,Guid)",
|
||||
|
||||
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))",
|
||||
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)",
|
||||
@ -166,10 +177,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
createMediaStreamsTableCommand,
|
||||
"create index if not exists idx_mediastreams1 on mediastreams(ItemId)",
|
||||
|
||||
//pragmas
|
||||
"pragma temp_store = memory",
|
||||
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
_connection.RunQueries(queries, Logger);
|
||||
@ -258,12 +265,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
_connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT");
|
||||
|
||||
string[] postQueries =
|
||||
{
|
||||
{
|
||||
"create index if not exists idx_PresentationUniqueKey on TypedBaseItems(PresentationUniqueKey)",
|
||||
"create index if not exists idx_GuidType on TypedBaseItems(Guid,Type)",
|
||||
"create index if not exists idx_Type on TypedBaseItems(Type)",
|
||||
"create index if not exists idx_TopParentId on TypedBaseItems(TopParentId)",
|
||||
"create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)"
|
||||
};
|
||||
"create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)",
|
||||
"create index if not exists idx_TypeTopParentId2 on TypedBaseItems(TopParentId,MediaType,IsVirtualItem)",
|
||||
"create index if not exists idx_TypeTopParentId3 on TypedBaseItems(TopParentId,IsFolder,IsVirtualItem)",
|
||||
"create index if not exists idx_TypeTopParentId4 on TypedBaseItems(TopParentId,Type,IsVirtualItem)",
|
||||
"create index if not exists idx_TypeTopParentId5 on TypedBaseItems(TopParentId,IsVirtualItem)"
|
||||
};
|
||||
|
||||
_connection.RunQueries(postQueries, Logger);
|
||||
|
||||
@ -869,15 +881,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
_saveItemCommand.GetParameter(index++).Value = item.Album;
|
||||
|
||||
var season = item as Season;
|
||||
if (season != null && season.IsVirtualItem.HasValue)
|
||||
{
|
||||
_saveItemCommand.GetParameter(index++).Value = season.IsVirtualItem.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_saveItemCommand.GetParameter(index++).Value = null;
|
||||
}
|
||||
_saveItemCommand.GetParameter(index++).Value = item.IsVirtualItem || (!item.IsFolder && item.LocationType == LocationType.Virtual);
|
||||
|
||||
var hasSeries = item as IHasSeries;
|
||||
if (hasSeries != null)
|
||||
@ -1306,10 +1310,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
item.CriticRatingSummary = reader.GetString(57);
|
||||
}
|
||||
|
||||
var season = item as Season;
|
||||
if (season != null && !reader.IsDBNull(58))
|
||||
if (!reader.IsDBNull(58))
|
||||
{
|
||||
season.IsVirtualItem = reader.GetBoolean(58);
|
||||
item.IsVirtualItem = reader.GetBoolean(58);
|
||||
}
|
||||
|
||||
return item;
|
||||
@ -1461,7 +1464,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
/// or
|
||||
/// cancellationToken
|
||||
/// </exception>
|
||||
public async Task SaveChapters(Guid id, IEnumerable<ChapterInfo> chapters, CancellationToken cancellationToken)
|
||||
public async Task SaveChapters(Guid id, List<ChapterInfo> chapters, CancellationToken cancellationToken)
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
@ -2719,8 +2722,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
if (query.LocationTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("LocationType=@LocationType");
|
||||
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.LocationTypes[0].ToString();
|
||||
if (query.LocationTypes[0] == LocationType.Virtual && _config.Configuration.SchemaVersion >= 90)
|
||||
{
|
||||
query.IsVirtualItem = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("LocationType=@LocationType");
|
||||
cmd.Parameters.Add(cmd, "@LocationType", DbType.String).Value = query.LocationTypes[0].ToString();
|
||||
}
|
||||
}
|
||||
else if (query.LocationTypes.Length > 1)
|
||||
{
|
||||
@ -2730,8 +2740,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
}
|
||||
if (query.ExcludeLocationTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("LocationType<>@ExcludeLocationTypes");
|
||||
cmd.Parameters.Add(cmd, "@ExcludeLocationTypes", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
|
||||
if (query.ExcludeLocationTypes[0] == LocationType.Virtual && _config.Configuration.SchemaVersion >= 90)
|
||||
{
|
||||
query.IsVirtualItem = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("LocationType<>@ExcludeLocationTypes");
|
||||
cmd.Parameters.Add(cmd, "@ExcludeLocationTypes", DbType.String).Value = query.ExcludeLocationTypes[0].ToString();
|
||||
}
|
||||
}
|
||||
else if (query.ExcludeLocationTypes.Length > 1)
|
||||
{
|
||||
@ -2739,6 +2756,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
whereClauses.Add("LocationType not in (" + val + ")");
|
||||
}
|
||||
if (query.IsVirtualItem.HasValue)
|
||||
{
|
||||
whereClauses.Add("IsVirtualItem=@IsVirtualItem");
|
||||
cmd.Parameters.Add(cmd, "@IsVirtualItem", DbType.Boolean).Value = query.IsVirtualItem.Value;
|
||||
}
|
||||
if (query.MediaTypes.Length == 1)
|
||||
{
|
||||
whereClauses.Add("MediaType=@MediaTypes");
|
||||
@ -3734,7 +3756,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task SaveMediaStreams(Guid id, IEnumerable<MediaStream> streams, CancellationToken cancellationToken)
|
||||
public async Task SaveMediaStreams(Guid id, List<MediaStream> streams, CancellationToken cancellationToken)
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
|
@ -16,11 +16,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
|
||||
public SqliteUserDataRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
||||
{
|
||||
_appPaths = appPaths;
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||
}
|
||||
|
||||
protected override bool EnableConnectionPooling
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -39,11 +43,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(IDbConnector dbConnector)
|
||||
public async Task Initialize()
|
||||
{
|
||||
var dbFile = Path.Combine(_appPaths.DataPath, "userdata_v2.db");
|
||||
|
||||
_connection = await dbConnector.Connect(dbFile, false).ConfigureAwait(false);
|
||||
_connection = await CreateConnection(false).ConfigureAwait(false);
|
||||
|
||||
string[] queries = {
|
||||
|
||||
|
@ -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"
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
};
|
||||
|
||||
|
@ -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"
|
||||
};
|
||||
|
||||
|
@ -573,7 +573,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
|
||||
await displayPreferencesRepo.Initialize().ConfigureAwait(false);
|
||||
await ConfigureUserDataRepositories().ConfigureAwait(false);
|
||||
await itemRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
|
||||
await itemRepo.Initialize().ConfigureAwait(false);
|
||||
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
|
||||
await ConfigureNotificationsRepository().ConfigureAwait(false);
|
||||
progress.Report(100);
|
||||
@ -691,7 +691,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
{
|
||||
var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector());
|
||||
|
||||
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
|
||||
await repo.Initialize().ConfigureAwait(false);
|
||||
|
||||
return repo;
|
||||
}
|
||||
@ -746,7 +746,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
{
|
||||
var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector());
|
||||
|
||||
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
|
||||
await repo.Initialize().ConfigureAwait(false);
|
||||
|
||||
((UserDataManager)UserDataManager).Repository = repo;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user