aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs3
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs4
-rw-r--r--MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj17
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs4
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs5
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs52
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteMediaStreamsRepository.cs4
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs4
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs4
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteShrinkMemoryTimer.cs84
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs4
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs5
-rw-r--r--MediaBrowser.Server.Implementations/swagger-ui/index.html80
13 files changed, 151 insertions, 119 deletions
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index ee10fb934..27ce90787 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -74,7 +74,8 @@ namespace MediaBrowser.Server.Implementations.Drawing
try
{
- sizeDictionary = jsonSerializer.DeserializeFromFile<Dictionary<Guid, ImageSize>>(ImageSizeFile);
+ sizeDictionary = jsonSerializer.DeserializeFromFile<Dictionary<Guid, ImageSize>>(ImageSizeFile) ??
+ new Dictionary<Guid, ImageSize>();
}
catch (FileNotFoundException)
{
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
index c50588f95..29dce6747 100644
--- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -5,7 +5,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Logging;
using ServiceStack;
-using ServiceStack.Configuration;
using ServiceStack.Host;
using ServiceStack.Host.Handlers;
using ServiceStack.Host.HttpListener;
@@ -58,9 +57,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public HttpListenerHost(IApplicationHost applicationHost, ILogManager logManager, string serviceName, string handlerPath, string defaultRedirectPath, params Assembly[] assembliesWithServices)
: base(serviceName, assembliesWithServices)
{
- // https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.IntegrationTests/Web.config#L4
- Licensing.RegisterLicense("1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBCdXNpbmVzcyxUeXBlOkJ1c2luZXNzLEhhc2g6UHVNTVRPclhvT2ZIbjQ5MG5LZE1mUTd5RUMzQnBucTFEbTE3TDczVEF4QUNMT1FhNXJMOWkzVjFGL2ZkVTE3Q2pDNENqTkQyUktRWmhvUVBhYTBiekJGUUZ3ZE5aZHFDYm9hL3lydGlwUHI5K1JsaTBYbzNsUC85cjVJNHE5QVhldDN6QkE4aTlvdldrdTgyTk1relY2eis2dFFqTThYN2lmc0JveHgycFdjPSxFeHBpcnk6MjAxMy0wMS0wMX0=");
-
DefaultRedirectPath = defaultRedirectPath;
ServerName = serviceName;
HandlerPath = handlerPath;
diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
index f22a96455..39966f0d7 100644
--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
@@ -37,18 +37,23 @@
<Reference Include="Alchemy">
<HintPath>..\packages\Alchemy.2.2.1\lib\net40\Alchemy.dll</HintPath>
</Reference>
- <Reference Include="ServiceStack, Version=3.9.70.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="ServiceStack, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.dll</HintPath>
</Reference>
- <Reference Include="ServiceStack.Client">
+ <Reference Include="ServiceStack.Client, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.Client.dll</HintPath>
</Reference>
- <Reference Include="ServiceStack.Interfaces, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="ServiceStack.Common, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\ThirdParty\ServiceStack\ServiceStack.Common.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Interfaces, Version=4.0.0.0, Culture=neutral, PublicKeyToken=e06fbc6124f57c43, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath>
</Reference>
- <Reference Include="ServiceStack.Text, Version=3.9.70.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="ServiceStack.Text, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.Text.dll</HintPath>
</Reference>
@@ -143,6 +148,7 @@
<Compile Include="Persistence\SqliteMediaStreamsRepository.cs" />
<Compile Include="Persistence\SqliteNotificationsRepository.cs" />
<Compile Include="Persistence\SqliteProviderInfoRepository.cs" />
+ <Compile Include="Persistence\SqliteShrinkMemoryTimer.cs" />
<Compile Include="Persistence\TypeMapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\ImageSaver.cs" />
@@ -237,9 +243,6 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Localization\Ratings\ca.txt" />
- <Content Include="swagger-ui\index.html">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs
index 9121ae87b..075ef4239 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteChapterRepository.cs
@@ -44,7 +44,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_chapters on chapters(ItemId, ChapterIndex)",
//pragmas
- "pragma temp_store = memory"
+ "pragma temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs
index 09f438aef..9f6ec0f24 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs
@@ -86,8 +86,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
"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 temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs
index 893d6ea62..200898a62 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs
@@ -124,18 +124,24 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_ChildrenIds on ChildrenIds(ParentId,ItemId)",
//pragmas
- "pragma temp_store = memory"
+ "pragma temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
PrepareStatements();
-
+
_mediaStreamsRepository.Initialize();
_providerInfoRepository.Initialize();
_chapterRepository.Initialize();
+
+ _shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
+ private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
+
/// <summary>
/// The _write lock
/// </summary>
@@ -402,6 +408,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
+ if (_shrinkMemoryTimer != null)
+ {
+ _shrinkMemoryTimer.Dispose();
+ _shrinkMemoryTimer = null;
+ }
+
if (_connection != null)
{
if (_connection.IsOpen())
@@ -412,30 +424,30 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection.Dispose();
_connection = null;
}
+
+ if (_chapterRepository != null)
+ {
+ _chapterRepository.Dispose();
+ _chapterRepository = null;
+ }
+
+ if (_mediaStreamsRepository != null)
+ {
+ _mediaStreamsRepository.Dispose();
+ _mediaStreamsRepository = null;
+ }
+
+ if (_providerInfoRepository != null)
+ {
+ _providerInfoRepository.Dispose();
+ _providerInfoRepository = null;
+ }
}
}
catch (Exception ex)
{
_logger.ErrorException("Error disposing database", ex);
}
-
- if (_chapterRepository != null)
- {
- _chapterRepository.Dispose();
- _chapterRepository = null;
- }
-
- if (_mediaStreamsRepository != null)
- {
- _mediaStreamsRepository.Dispose();
- _mediaStreamsRepository = null;
- }
-
- if (_providerInfoRepository != null)
- {
- _providerInfoRepository.Dispose();
- _providerInfoRepository = null;
- }
}
}
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteMediaStreamsRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteMediaStreamsRepository.cs
index ba189396a..b898398d8 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteMediaStreamsRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteMediaStreamsRepository.cs
@@ -43,7 +43,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_mediastreams on mediastreams(ItemId, StreamIndex)",
//pragmas
- "pragma temp_store = memory"
+ "pragma temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs
index c5f391765..0f9b4295e 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs
@@ -45,7 +45,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_Notifications on Notifications(Id, UserId)",
//pragmas
- "pragma temp_store = memory"
+ "pragma temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs
index 8972beb05..5d836b090 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteProviderInfoRepository.cs
@@ -42,7 +42,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_providerinfos on providerinfos(ItemId, ProviderId)",
//pragmas
- "pragma temp_store = memory"
+ "pragma temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteShrinkMemoryTimer.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteShrinkMemoryTimer.cs
new file mode 100644
index 000000000..01784d540
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteShrinkMemoryTimer.cs
@@ -0,0 +1,84 @@
+using MediaBrowser.Model.Logging;
+using System;
+using System.Data;
+using System.Threading;
+
+namespace MediaBrowser.Server.Implementations.Persistence
+{
+ class SqliteShrinkMemoryTimer : IDisposable
+ {
+ private Timer _shrinkMemoryTimer;
+
+ private readonly SemaphoreSlim _writeLock;
+ private readonly ILogger _logger;
+ private readonly IDbConnection _connection;
+
+ public SqliteShrinkMemoryTimer(IDbConnection connection, SemaphoreSlim writeLock, ILogger logger)
+ {
+ _connection = connection;
+ _writeLock = writeLock;
+ _logger = logger;
+
+ _shrinkMemoryTimer = new Timer(TimerCallback, null, TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30));
+ }
+
+ private async void TimerCallback(object state)
+ {
+ await _writeLock.WaitAsync(CancellationToken.None).ConfigureAwait(false);
+
+ IDbTransaction transaction = null;
+
+ try
+ {
+ transaction = _connection.BeginTransaction();
+
+ using (var cmd = _connection.CreateCommand())
+ {
+ cmd.Transaction = transaction;
+ cmd.CommandText = "pragma shrink_memory";
+ cmd.ExecuteNonQuery();
+ }
+
+ transaction.Commit();
+ }
+ catch (OperationCanceledException)
+ {
+ if (transaction != null)
+ {
+ transaction.Rollback();
+ }
+
+ throw;
+ }
+ catch (Exception e)
+ {
+ _logger.ErrorException("Failed to save items:", e);
+
+ if (transaction != null)
+ {
+ transaction.Rollback();
+ }
+
+ throw;
+ }
+ finally
+ {
+ if (transaction != null)
+ {
+ transaction.Dispose();
+ }
+
+ _writeLock.Release();
+ }
+ }
+
+ public void Dispose()
+ {
+ if (_shrinkMemoryTimer != null)
+ {
+ _shrinkMemoryTimer.Dispose();
+ _shrinkMemoryTimer = null;
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs
index fa195859b..d3f9100b1 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs
@@ -72,7 +72,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create unique index if not exists userdataindex on userdata (key, userId)",
//pragmas
- "pragma temp_store = memory"
+ "pragma temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs
index 222cc9422..d97a55ae6 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs
@@ -77,8 +77,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create table if not exists users (guid GUID primary key, data BLOB)",
"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 temp_store = memory",
+
+ "pragma shrink_memory"
};
_connection.RunQueries(queries, _logger);
diff --git a/MediaBrowser.Server.Implementations/swagger-ui/index.html b/MediaBrowser.Server.Implementations/swagger-ui/index.html
deleted file mode 100644
index 49f983a72..000000000
--- a/MediaBrowser.Server.Implementations/swagger-ui/index.html
+++ /dev/null
@@ -1,80 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>Swagger UI</title>
- <link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
- <link href='css/hightlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
- <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
- <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
- <script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
- <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
- <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
- <script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
- <script src='lib/underscore-min.js' type='text/javascript'></script>
- <script src='lib/backbone-min.js' type='text/javascript'></script>
- <script src='lib/swagger.js' type='text/javascript'></script>
- <script src='swagger-ui.js' type='text/javascript'></script>
- <script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
-
- <script type="text/javascript">
- $(function () {
- window.swaggerUi = new SwaggerUi({
- discoveryUrl: "../resources",
- apiKey: "special-key",
- dom_id:"swagger-ui-container",
- supportHeaderParams: false,
- supportedSubmitMethods: ['get', 'post', 'put'],
- onComplete: function(swaggerApi, swaggerUi){
- if(console) {
- console.log("Loaded SwaggerUI")
- console.log(swaggerApi);
- console.log(swaggerUi);
- }
- $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
- },
- onFailure: function(data) {
- if(console) {
- console.log("Unable to Load SwaggerUI");
- console.log(data);
- }
- },
- docExpansion: "none"
- });
-
- window.swaggerUi.load();
- });
-
- </script>
-</head>
-
-<body>
-<div id='header'>
- <div class="swagger-ui-wrap">
- <a id="logo" href="http://swagger.wordnik.com">swagger</a>
-
- <form id='api_selector'>
- <div class='input icon-btn'>
- <img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
- </div>
- <div class='input icon-btn'>
- <img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
- </div>
- <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl"
- type="text"/></div>
- <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
- <div class='input'><a id="explore" href="#">Explore</a></div>
- </form>
- </div>
-</div>
-
-<div id="message-bar" class="swagger-ui-wrap">
- &nbsp;
-</div>
-
-<div id="swagger-ui-container" class="swagger-ui-wrap">
-
-</div>
-
-</body>
-
-</html>