The Free Software Media System - Server Backend & API
fixed db disposals
Luke Pulverentieb612bd303b1
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.csindex 293a9019e8..0a2d6453af 100644--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs@@ -1,12 +1,8 @@using MediaBrowser.Controller.Dto;using MediaBrowser.Controller.Entities;-using MediaBrowser.Controller.Entities.Audio;-using MediaBrowser.Controller.Entities.Movies;-using MediaBrowser.Controller.Entities.TV;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Persistence;using MediaBrowser.Model.Dto;-using MediaBrowser.Model.Entities;using MediaBrowser.Model.Querying;using ServiceStack.ServiceHost;using System;diff --git a/MediaBrowser.Api/UserLibrary/YearsService.cs b/MediaBrowser.Api/UserLibrary/YearsService.csindex c7cd4ff242..b22a8dac35 100644--- a/MediaBrowser.Api/UserLibrary/YearsService.cs+++ b/MediaBrowser.Api/UserLibrary/YearsService.cs@@ -2,7 +2,6 @@using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Persistence;using ServiceStack.ServiceHost;-using System;using System.Collections.Generic;using System.Globalization;using System.Linq;diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.csindex d64067f434..042ef30ec4 100644--- a/MediaBrowser.Controller/IServerApplicationHost.cs+++ b/MediaBrowser.Controller/IServerApplicationHost.cs@@ -3,8 +3,15 @@ using MediaBrowser.Model.System;namespace MediaBrowser.Controller{+ /// <summary>+ /// Interface IServerApplicationHost+ /// </summary>public interface IServerApplicationHost : IApplicationHost{+ /// <summary>+ /// Gets the system info.+ /// </summary>+ /// <returns>SystemInfo.</returns>SystemInfo GetSystemInfo();}}diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.csindex 4f93f4b6e4..01b867bdb7 100644--- a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs+++ b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs@@ -1,4 +1,3 @@-using System.IO;using Funq;using MediaBrowser.Common;using MediaBrowser.Common.Extensions;@@ -17,6 +16,7 @@ using ServiceStack.WebHost.Endpoints.Support;using System;using System.Collections.Generic;using System.Globalization;+using System.IO;using System.Linq;using System.Net;using System.Net.WebSockets;@@ -498,6 +498,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer_logger.Info("Calling ServiceStack AppHost.Init");Init();}++ /// <summary>+ /// Releases the specified instance.+ /// </summary>+ /// <param name="instance">The instance.</param>+ public override void Release(object instance)+ {+ // Leave this empty so SS doesn't try to dispose our objects+ }}/// <summary>diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.csindex 6824442f16..6179af1cb9 100644--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs@@ -160,27 +160,30 @@ namespace MediaBrowser.Server.Implementations.Sqlite{try{- if (connection != null)+ lock (this){- if (EnableDelayedCommands)+ if (connection != null){- FlushOnDispose();+ if (EnableDelayedCommands)+ {+ FlushOnDispose();+ }++ if (connection.IsOpen())+ {+ connection.Close();+ }++ connection.Dispose();+ connection = null;}-- if (connection.IsOpen())++ if (FlushTimer != null){- connection.Close();+ FlushTimer.Dispose();+ FlushTimer = null;}-- connection.Dispose();- }-- if (FlushTimer != null)- {- FlushTimer.Dispose();- FlushTimer = null;}-}catch (Exception ex){@@ -195,13 +198,13 @@ namespace MediaBrowser.Server.Implementations.Sqliteprivate void FlushOnDispose(){// If we're not already flushing, do it now- if (!IsFlushing)+ if (!_isFlushing){Flush(null);}// Don't dispose in the middle of a flush- while (IsFlushing)+ while (_isFlushing){Thread.Sleep(25);}@@ -225,7 +228,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite/// <summary>/// The is flushing/// </summary>- private bool IsFlushing;+ private bool _isFlushing;/// <summary>/// Flushes the specified sender.@@ -241,12 +244,12 @@ namespace MediaBrowser.Server.Implementations.Sqlitereturn;}- if (IsFlushing)+ if (_isFlushing){return;}- IsFlushing = true;+ _isFlushing = true;var numCommands = 0;using (var tran = connection.BeginTransaction())@@ -278,7 +281,7 @@ namespace MediaBrowser.Server.Implementations.SqliteLogger.Debug("SQL Delayed writer executed " + numCommands + " commands");FlushTimer.Change(TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1));- IsFlushing = false;+ _isFlushing = false;}/// <summary>diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.csindex 94a06020e2..18916e99e2 100644--- a/MediaBrowser.ServerApplication/ApplicationHost.cs+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs@@ -159,6 +159,9 @@ namespace MediaBrowser.ServerApplication/// </summary>/// <value>The user data repository.</value>private IUserDataRepository UserDataRepository { get; set; }+ private IUserRepository UserRepository { get; set; }+ private IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }+ private IItemRepository ItemRepository { get; set; }/// <summary>/// The full path to our startmenu shortcut@@ -239,6 +242,15 @@ namespace MediaBrowser.ServerApplicationUserDataRepository = new SQLiteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);RegisterSingleInstance(UserDataRepository);+ UserRepository = new SQLiteUserRepository(ApplicationPaths, JsonSerializer, LogManager);+ RegisterSingleInstance(UserRepository);++ DisplayPreferencesRepository = new SQLiteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);+ RegisterSingleInstance(DisplayPreferencesRepository);++ ItemRepository = new SQLiteItemRepository(ApplicationPaths, JsonSerializer, LogManager);+ RegisterSingleInstance(ItemRepository);+UserManager = new UserManager(Logger, ServerConfigurationManager, UserDataRepository);RegisterSingleInstance(UserManager);@@ -299,11 +311,9 @@ namespace MediaBrowser.ServerApplication/// <returns>Task.</returns>private async Task ConfigureDisplayPreferencesRepositories(){- var repository = new SQLiteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);-- await repository.Initialize().ConfigureAwait(false);+ await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);- ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = repository;+ ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = DisplayPreferencesRepository;}/// <summary>@@ -312,11 +322,9 @@ namespace MediaBrowser.ServerApplication/// <returns>Task.</returns>private async Task ConfigureItemRepositories(){- var repository = new SQLiteItemRepository(ApplicationPaths, JsonSerializer, LogManager);+ await ItemRepository.Initialize().ConfigureAwait(false);- await repository.Initialize().ConfigureAwait(false);-- ((LibraryManager)LibraryManager).ItemRepository = repository;+ ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;}/// <summary>@@ -328,13 +336,15 @@ namespace MediaBrowser.ServerApplicationreturn UserDataRepository.Initialize();}+ /// <summary>+ /// Configures the user repositories.+ /// </summary>+ /// <returns>Task.</returns>private async Task ConfigureUserRepositories(){- var repository = new SQLiteUserRepository(ApplicationPaths, JsonSerializer, LogManager);+ await UserRepository.Initialize().ConfigureAwait(false);- await repository.Initialize().ConfigureAwait(false);-- ((UserManager)UserManager).UserRepository = repository;+ ((UserManager)UserManager).UserRepository = UserRepository;}/// <summary>@@ -553,21 +563,5 @@ namespace MediaBrowser.ServerApplicationprocess.WaitForExit();}}-- /// <summary>- /// Gets the repository.- /// </summary>- /// <typeparam name="T"></typeparam>- /// <param name="repositories">The repositories.</param>- /// <param name="name">The name.</param>- /// <returns>``0.</returns>- private T GetRepository<T>(IEnumerable<T> repositories, string name)- where T : class, IRepository- {- var enumerable = repositories as T[] ?? repositories.ToArray();-- return enumerable.FirstOrDefault(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)) ??- enumerable.FirstOrDefault();- }}}diff --git a/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs b/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.csindex ae898f0f9a..bf4eb6e917 100644--- a/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs+++ b/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs@@ -1,5 +1,4 @@-using System.Windows;-using MediaBrowser.Controller.Entities;+using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Plugins;using MediaBrowser.Model.Logging;@@ -7,6 +6,7 @@ using MediaBrowser.ServerApplication.Controls;using System.Collections.Generic;using System.Linq;using System.Threading;+using System.Windows;using System.Windows.Controls.Primitives;namespace MediaBrowser.ServerApplication.EntryPointsdiff --git a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.csindex 056e50a780..a6d505d198 100644--- a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs+++ b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs@@ -1,6 +1,4 @@-using System.Linq;-using System.Threading;-using MediaBrowser.Common.Events;+using MediaBrowser.Common.Events;using MediaBrowser.Common.Net;using MediaBrowser.Common.Plugins;using MediaBrowser.Common.ScheduledTasks;@@ -15,6 +13,8 @@ using MediaBrowser.Model.Logging;using MediaBrowser.Model.Tasks;using MediaBrowser.Model.Updates;using System;+using System.Linq;+using System.Threading;namespace MediaBrowser.ServerApplication.EntryPoints{