mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 11:57:55 +02:00
remove shrink mem timer
This commit is contained in:
parent
e15ea55b56
commit
ee2fbf59d0
8 changed files with 1 additions and 146 deletions
|
@ -242,7 +242,6 @@
|
||||||
<Compile Include="Persistence\SqliteMediaStreamsRepository.cs" />
|
<Compile Include="Persistence\SqliteMediaStreamsRepository.cs" />
|
||||||
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
|
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
|
||||||
<Compile Include="Persistence\SqliteProviderInfoRepository.cs" />
|
<Compile Include="Persistence\SqliteProviderInfoRepository.cs" />
|
||||||
<Compile Include="Persistence\SqliteShrinkMemoryTimer.cs" />
|
|
||||||
<Compile Include="Persistence\TypeMapper.cs" />
|
<Compile Include="Persistence\TypeMapper.cs" />
|
||||||
<Compile Include="Photos\BaseDynamicImageProvider.cs" />
|
<Compile Include="Photos\BaseDynamicImageProvider.cs" />
|
||||||
<Compile Include="Playlists\ManualPlaylistsFolder.cs" />
|
<Compile Include="Playlists\ManualPlaylistsFolder.cs" />
|
||||||
|
|
|
@ -32,8 +32,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_logger = logManager.GetLogger(GetType().Name);
|
_logger = logManager.GetLogger(GetType().Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the connection to the database
|
/// Opens the connection to the database
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -54,8 +52,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_connection.RunQueries(queries, _logger);
|
_connection.RunQueries(queries, _logger);
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -286,12 +282,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (_shrinkMemoryTimer != null)
|
|
||||||
{
|
|
||||||
_shrinkMemoryTimer.Dispose();
|
|
||||||
_shrinkMemoryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_connection != null)
|
if (_connection != null)
|
||||||
{
|
{
|
||||||
if (_connection.IsOpen())
|
if (_connection.IsOpen())
|
||||||
|
|
|
@ -21,7 +21,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
|
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
|
||||||
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
|
|
||||||
private readonly IServerApplicationPaths _appPaths;
|
private readonly IServerApplicationPaths _appPaths;
|
||||||
|
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
|
@ -61,8 +60,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_connection.RunQueries(queries, _logger);
|
_connection.RunQueries(queries, _logger);
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareStatements()
|
private void PrepareStatements()
|
||||||
|
@ -446,12 +443,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (_shrinkMemoryTimer != null)
|
|
||||||
{
|
|
||||||
_shrinkMemoryTimer.Dispose();
|
|
||||||
_shrinkMemoryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_connection != null)
|
if (_connection != null)
|
||||||
{
|
{
|
||||||
if (_connection.IsOpen())
|
if (_connection.IsOpen())
|
||||||
|
|
|
@ -130,12 +130,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
_mediaStreamsRepository.Initialize();
|
_mediaStreamsRepository.Initialize();
|
||||||
_chapterRepository.Initialize();
|
_chapterRepository.Initialize();
|
||||||
|
|
||||||
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _write lock
|
/// The _write lock
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -430,12 +426,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (_shrinkMemoryTimer != null)
|
|
||||||
{
|
|
||||||
_shrinkMemoryTimer.Dispose();
|
|
||||||
_shrinkMemoryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
_writeLock.Wait();
|
_writeLock.Wait();
|
||||||
|
|
||||||
if (_connection != null)
|
if (_connection != null)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Globalization;
|
using MediaBrowser.Controller.Persistence;
|
||||||
using MediaBrowser.Controller.Persistence;
|
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
|
@ -21,8 +20,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
private IDbCommand _deleteStreamsCommand;
|
private IDbCommand _deleteStreamsCommand;
|
||||||
private IDbCommand _saveStreamCommand;
|
private IDbCommand _saveStreamCommand;
|
||||||
|
|
||||||
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
|
|
||||||
|
|
||||||
public SqliteMediaStreamsRepository(IDbConnection connection, ILogManager logManager)
|
public SqliteMediaStreamsRepository(IDbConnection connection, ILogManager logManager)
|
||||||
{
|
{
|
||||||
_connection = connection;
|
_connection = connection;
|
||||||
|
@ -64,8 +61,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
AddRefFramesCommand();
|
AddRefFramesCommand();
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddPixelFormatColumnCommand()
|
private void AddPixelFormatColumnCommand()
|
||||||
|
@ -563,12 +558,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (_shrinkMemoryTimer != null)
|
|
||||||
{
|
|
||||||
_shrinkMemoryTimer.Dispose();
|
|
||||||
_shrinkMemoryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_connection != null)
|
if (_connection != null)
|
||||||
{
|
{
|
||||||
if (_connection.IsOpen())
|
if (_connection.IsOpen())
|
||||||
|
|
|
@ -26,8 +26,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_logger = logManager.GetLogger(GetType().Name);
|
_logger = logManager.GetLogger(GetType().Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the repository
|
/// Gets the name of the repository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -66,8 +64,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
AddItemDateModifiedCommand();
|
AddItemDateModifiedCommand();
|
||||||
|
|
||||||
PrepareStatements();
|
PrepareStatements();
|
||||||
|
|
||||||
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly string[] StatusColumns =
|
private static readonly string[] StatusColumns =
|
||||||
|
@ -307,12 +303,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (_shrinkMemoryTimer != null)
|
|
||||||
{
|
|
||||||
_shrinkMemoryTimer.Dispose();
|
|
||||||
_shrinkMemoryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_connection != null)
|
if (_connection != null)
|
||||||
{
|
{
|
||||||
if (_connection.IsOpen())
|
if (_connection.IsOpen())
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
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(10));
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -55,8 +55,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_logger = logManager.GetLogger(GetType().Name);
|
_logger = logManager.GetLogger(GetType().Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the connection to the database
|
/// Opens the connection to the database
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -80,8 +78,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
};
|
};
|
||||||
|
|
||||||
_connection.RunQueries(queries, _logger);
|
_connection.RunQueries(queries, _logger);
|
||||||
|
|
||||||
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -402,12 +398,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
lock (_disposeLock)
|
lock (_disposeLock)
|
||||||
{
|
{
|
||||||
if (_shrinkMemoryTimer != null)
|
|
||||||
{
|
|
||||||
_shrinkMemoryTimer.Dispose();
|
|
||||||
_shrinkMemoryTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_connection != null)
|
if (_connection != null)
|
||||||
{
|
{
|
||||||
if (_connection.IsOpen())
|
if (_connection.IsOpen())
|
||||||
|
|
Loading…
Reference in a new issue