diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-09-22 16:35:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-22 16:35:54 -0400 |
| commit | a31006577432efd25de2fe0e32a3900af7b0907a (patch) | |
| tree | 60cde7a83b451889dcfb7dc88f02df6ffd6e90f1 /Emby.Server.Implementations | |
| parent | 8586c9f6a7dc8562da1f6bca2b3ce53398dd03b5 (diff) | |
| parent | c25db09e37ccdf158e607792cf678b1ed22b13a7 (diff) | |
Merge pull request #2906 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Server.Implementations')
9 files changed, 133 insertions, 73 deletions
diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index 3dcc50ba3..1ae8e5e66 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -10,21 +10,40 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Querying; using SQLitePCL.pretty; using MediaBrowser.Model.Extensions; +using MediaBrowser.Model.IO; namespace Emby.Server.Implementations.Activity { public class ActivityRepository : BaseSqliteRepository, IActivityRepository { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + protected IFileSystem FileSystem { get; private set; } - public ActivityRepository(ILogger logger, IServerApplicationPaths appPaths) + public ActivityRepository(ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem) : base(logger) { DbFilePath = Path.Combine(appPaths.DataPath, "activitylog.db"); + FileSystem = fileSystem; } public void Initialize() { + try + { + InitializeInternal(); + } + catch (Exception ex) + { + Logger.ErrorException("Error loading database file. Will reset and retry.", ex); + + FileSystem.DeleteFile(DbFilePath); + + InitializeInternal(); + } + } + + private void InitializeInternal() + { using (var connection = CreateConnection()) { RunDefaultInitialization(connection); diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 47b969eca..ba43c7f35 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -879,7 +879,7 @@ namespace Emby.Server.Implementations // This is only needed for disposal purposes. If removing this, make sure to have the manager handle disposing it RegisterSingleInstance(UserRepository); - var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager.GetLogger("SqliteDisplayPreferencesRepository"), JsonSerializer, ApplicationPaths, MemoryStreamFactory); + var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager.GetLogger("SqliteDisplayPreferencesRepository"), JsonSerializer, ApplicationPaths, MemoryStreamFactory, FileSystemManager); DisplayPreferencesRepository = displayPreferencesRepo; RegisterSingleInstance(DisplayPreferencesRepository); @@ -997,7 +997,7 @@ namespace Emby.Server.Implementations EncodingManager = new EncodingManager(FileSystemManager, Logger, MediaEncoder, ChapterManager, LibraryManager); RegisterSingleInstance(EncodingManager); - var sharingRepo = new SharingRepository(LogManager.GetLogger("SharingRepository"), ApplicationPaths); + var sharingRepo = new SharingRepository(LogManager.GetLogger("SharingRepository"), ApplicationPaths, FileSystemManager); sharingRepo.Initialize(); // This is only needed for disposal purposes. If removing this, make sure to have the manager handle disposing it RegisterSingleInstance<ISharingRepository>(sharingRepo); @@ -1351,7 +1351,7 @@ namespace Emby.Server.Implementations private IActivityRepository GetActivityLogRepository() { - var repo = new ActivityRepository(LogManager.GetLogger("ActivityRepository"), ServerConfigurationManager.ApplicationPaths); + var repo = new ActivityRepository(LogManager.GetLogger("ActivityRepository"), ServerConfigurationManager.ApplicationPaths, FileSystemManager); repo.Initialize(); diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs index a34c90cb4..d207c8d4f 100644 --- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs +++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs @@ -108,37 +108,49 @@ namespace Emby.Server.Implementations.Data var db = SQLite3.Open(DbFilePath, connectionFlags, null); - if (string.IsNullOrWhiteSpace(_defaultWal)) + try { - _defaultWal = db.Query("PRAGMA journal_mode").SelectScalarString().First(); + if (string.IsNullOrWhiteSpace(_defaultWal)) + { + _defaultWal = db.Query("PRAGMA journal_mode").SelectScalarString().First(); - Logger.Info("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal); - } + Logger.Info("Default journal_mode for {0} is {1}", DbFilePath, _defaultWal); + } - var queries = new List<string> - { - //"PRAGMA cache size=-10000" - //"PRAGMA read_uncommitted = true", - "PRAGMA synchronous=Normal" - }; + var queries = new List<string> + { + //"PRAGMA cache size=-10000" + //"PRAGMA read_uncommitted = true", + "PRAGMA synchronous=Normal" + }; - if (CacheSize.HasValue) - { - queries.Add("PRAGMA cache_size=" + CacheSize.Value.ToString(CultureInfo.InvariantCulture)); - } + if (CacheSize.HasValue) + { + queries.Add("PRAGMA cache_size=" + CacheSize.Value.ToString(CultureInfo.InvariantCulture)); + } - if (EnableTempStoreMemory) - { - queries.Add("PRAGMA temp_store = memory"); + if (EnableTempStoreMemory) + { + queries.Add("PRAGMA temp_store = memory"); + } + else + { + queries.Add("PRAGMA temp_store = file"); + } + + foreach (var query in queries) + { + db.Execute(query); + } } - else + catch { - queries.Add("PRAGMA temp_store = file"); - } + using (db) + { - foreach (var query in queries) - { - db.Execute(query); + } + + throw; } _connection = new ManagedConnection(db, false); @@ -265,29 +277,34 @@ namespace Emby.Server.Implementations.Data { if (dispose) { - try + DisposeConnection(); + } + } + + private void DisposeConnection() + { + try + { + lock (_disposeLock) { - lock (_disposeLock) + using (WriteLock.Write()) { - using (WriteLock.Write()) + if (_connection != null) { - if (_connection != null) + using (_connection) { - using (_connection) - { - - } - _connection = null; + _connection.Close(); } - - CloseConnection(); + _connection = null; } + + CloseConnection(); } } - catch (Exception ex) - { - Logger.ErrorException("Error disposing database", ex); - } + } + catch (Exception ex) + { + Logger.ErrorException("Error disposing database", ex); } } diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs index 89664d158..1901ce848 100644 --- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs @@ -19,12 +19,14 @@ namespace Emby.Server.Implementations.Data public class SqliteDisplayPreferencesRepository : BaseSqliteRepository, IDisplayPreferencesRepository { private readonly IMemoryStreamFactory _memoryStreamProvider; + protected IFileSystem FileSystem { get; private set; } - public SqliteDisplayPreferencesRepository(ILogger logger, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IMemoryStreamFactory memoryStreamProvider) + public SqliteDisplayPreferencesRepository(ILogger logger, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IMemoryStreamFactory memoryStreamProvider, IFileSystem fileSystem) : base(logger) { _jsonSerializer = jsonSerializer; _memoryStreamProvider = memoryStreamProvider; + FileSystem = fileSystem; DbFilePath = Path.Combine(appPaths.DataPath, "displaypreferences.db"); } @@ -45,11 +47,27 @@ namespace Emby.Server.Implementations.Data /// </summary> private readonly IJsonSerializer _jsonSerializer; + public void Initialize() + { + try + { + InitializeInternal(); + } + catch (Exception ex) + { + Logger.ErrorException("Error loading database file. Will reset and retry.", ex); + + FileSystem.DeleteFile(DbFilePath); + + InitializeInternal(); + } + } + /// <summary> /// Opens the connection to the database /// </summary> /// <returns>Task.</returns> - public void Initialize() + private void InitializeInternal() { using (var connection = CreateConnection()) { diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 89ffb0fce..987b1df39 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -120,13 +120,13 @@ namespace Emby.Server.Implementations.Data protected override void CloseConnection() { - base.CloseConnection(); - if (_shrinkMemoryTimer != null) { _shrinkMemoryTimer.Dispose(); _shrinkMemoryTimer = null; } + + base.CloseConnection(); } /// <summary> diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 1854829a2..5ef910e51 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1642,6 +1642,8 @@ namespace Emby.Server.Implementations.Dto return null; } + _logger.Info("Getting image size for item type {0}", item.GetType().Name); + try { size = _imageProcessor.GetImageSize(imageInfo); @@ -1673,22 +1675,6 @@ namespace Emby.Server.Implementations.Dto return null; } - var photo = item as Photo; - if (photo != null && photo.Orientation.HasValue) - { - switch (photo.Orientation.Value) - { - case ImageOrientation.LeftBottom: - case ImageOrientation.LeftTop: - case ImageOrientation.RightBottom: - case ImageOrientation.RightTop: - var temp = height; - height = width; - width = temp; - break; - } - } - return width / height; } } diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index f5a1fe246..3e0565343 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -360,7 +360,7 @@ namespace Emby.Server.Implementations.HttpServer if (IsNotModified(requestContext, cacheKey, lastDateModified, cacheDuration)) { AddAgeHeader(responseHeaders, lastDateModified); - AddExpiresHeader(responseHeaders, cacheKeyString, cacheDuration, noCache); + AddExpiresHeader(responseHeaders, cacheKeyString, cacheDuration); var result = new HttpResult(new byte[] { }, contentType ?? "text/html", HttpStatusCode.NotModified); @@ -370,7 +370,7 @@ namespace Emby.Server.Implementations.HttpServer } } - AddCachingHeaders(responseHeaders, cacheKeyString, lastDateModified, cacheDuration, noCache); + AddCachingHeaders(responseHeaders, cacheKeyString, lastDateModified, cacheDuration); return null; } @@ -555,7 +555,7 @@ namespace Emby.Server.Implementations.HttpServer /// <summary> /// Adds the caching responseHeaders. /// </summary> - private void AddCachingHeaders(IDictionary<string, string> responseHeaders, string cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, bool noCache) + private void AddCachingHeaders(IDictionary<string, string> responseHeaders, string cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration) { // Don't specify both last modified and Etag, unless caching unconditionally. They are redundant // https://developers.google.com/speed/docs/best-practices/caching#LeverageBrowserCaching @@ -565,11 +565,11 @@ namespace Emby.Server.Implementations.HttpServer responseHeaders["Last-Modified"] = lastDateModified.Value.ToString("r"); } - if (!noCache && cacheDuration.HasValue) + if (cacheDuration.HasValue) { responseHeaders["Cache-Control"] = "public, max-age=" + Convert.ToInt32(cacheDuration.Value.TotalSeconds); } - else if (!noCache && !string.IsNullOrEmpty(cacheKey)) + else if (!string.IsNullOrEmpty(cacheKey)) { responseHeaders["Cache-Control"] = "public"; } @@ -579,15 +579,15 @@ namespace Emby.Server.Implementations.HttpServer responseHeaders["pragma"] = "no-cache, no-store, must-revalidate"; } - AddExpiresHeader(responseHeaders, cacheKey, cacheDuration, noCache); + AddExpiresHeader(responseHeaders, cacheKey, cacheDuration); } /// <summary> /// Adds the expires header. /// </summary> - private void AddExpiresHeader(IDictionary<string, string> responseHeaders, string cacheKey, TimeSpan? cacheDuration, bool noCache) + private void AddExpiresHeader(IDictionary<string, string> responseHeaders, string cacheKey, TimeSpan? cacheDuration) { - if (!noCache && cacheDuration.HasValue) + if (cacheDuration.HasValue) { responseHeaders["Expires"] = DateTime.UtcNow.Add(cacheDuration.Value).ToString("r"); } diff --git a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs index ff152c9e9..f3a8a18ee 100644 --- a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs +++ b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs @@ -38,7 +38,7 @@ namespace Emby.Server.Implementations.Notifications } catch (Exception ex) { - Logger.ErrorException("Error loading notifications database file. Will reset and retry.", ex); + Logger.ErrorException("Error loading database file. Will reset and retry.", ex); FileSystem.DeleteFile(DbFilePath); diff --git a/Emby.Server.Implementations/Social/SharingRepository.cs b/Emby.Server.Implementations/Social/SharingRepository.cs index f306e76c4..f0b8cbd30 100644 --- a/Emby.Server.Implementations/Social/SharingRepository.cs +++ b/Emby.Server.Implementations/Social/SharingRepository.cs @@ -7,22 +7,42 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Social; using SQLitePCL.pretty; using MediaBrowser.Model.Extensions; +using MediaBrowser.Model.IO; namespace Emby.Server.Implementations.Social { public class SharingRepository : BaseSqliteRepository, ISharingRepository { - public SharingRepository(ILogger logger, IApplicationPaths appPaths) + protected IFileSystem FileSystem { get; private set; } + + public SharingRepository(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem) : base(logger) { + FileSystem = fileSystem; DbFilePath = Path.Combine(appPaths.DataPath, "shares.db"); } + public void Initialize() + { + try + { + InitializeInternal(); + } + catch (Exception ex) + { + Logger.ErrorException("Error loading database file. Will reset and retry.", ex); + + FileSystem.DeleteFile(DbFilePath); + + InitializeInternal(); + } + } + /// <summary> /// Opens the connection to the database /// </summary> /// <returns>Task.</returns> - public void Initialize() + private void InitializeInternal() { using (var connection = CreateConnection()) { |
