remove shrink mem timer

pull/702/head
Luke Pulverenti 10 years ago
parent e15ea55b56
commit ee2fbf59d0

@ -242,7 +242,6 @@
<Compile Include="Persistence\SqliteMediaStreamsRepository.cs" />
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
<Compile Include="Persistence\SqliteProviderInfoRepository.cs" />
<Compile Include="Persistence\SqliteShrinkMemoryTimer.cs" />
<Compile Include="Persistence\TypeMapper.cs" />
<Compile Include="Photos\BaseDynamicImageProvider.cs" />
<Compile Include="Playlists\ManualPlaylistsFolder.cs" />

@ -32,8 +32,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_logger = logManager.GetLogger(GetType().Name);
}
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
/// <summary>
/// Opens the connection to the database
/// </summary>
@ -54,8 +52,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection.RunQueries(queries, _logger);
PrepareStatements();
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
/// <summary>
@ -286,12 +282,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
_shrinkMemoryTimer = null;
}
if (_connection != null)
{
if (_connection.IsOpen())

@ -21,7 +21,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
private readonly ILogger _logger;
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
private readonly IServerApplicationPaths _appPaths;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
@ -61,8 +60,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection.RunQueries(queries, _logger);
PrepareStatements();
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
private void PrepareStatements()
@ -446,12 +443,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
_shrinkMemoryTimer = null;
}
if (_connection != null)
{
if (_connection.IsOpen())

@ -130,12 +130,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
_mediaStreamsRepository.Initialize();
_chapterRepository.Initialize();
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
/// <summary>
/// The _write lock
/// </summary>
@ -430,12 +426,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
_shrinkMemoryTimer = null;
}
_writeLock.Wait();
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.Logging;
using System;
@ -21,8 +20,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _deleteStreamsCommand;
private IDbCommand _saveStreamCommand;
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
public SqliteMediaStreamsRepository(IDbConnection connection, ILogManager logManager)
{
_connection = connection;
@ -64,8 +61,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
AddRefFramesCommand();
PrepareStatements();
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
private void AddPixelFormatColumnCommand()
@ -563,12 +558,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
_shrinkMemoryTimer = null;
}
if (_connection != null)
{
if (_connection.IsOpen())

@ -26,8 +26,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
_logger = logManager.GetLogger(GetType().Name);
}
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
/// <summary>
/// Gets the name of the repository
/// </summary>
@ -66,8 +64,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
AddItemDateModifiedCommand();
PrepareStatements();
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
private static readonly string[] StatusColumns =
@ -307,12 +303,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
_shrinkMemoryTimer = null;
}
if (_connection != null)
{
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);
}
private SqliteShrinkMemoryTimer _shrinkMemoryTimer;
/// <summary>
/// Opens the connection to the database
/// </summary>
@ -80,8 +78,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
};
_connection.RunQueries(queries, _logger);
_shrinkMemoryTimer = new SqliteShrinkMemoryTimer(_connection, _writeLock, _logger);
}
/// <summary>
@ -402,12 +398,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
lock (_disposeLock)
{
if (_shrinkMemoryTimer != null)
{
_shrinkMemoryTimer.Dispose();
_shrinkMemoryTimer = null;
}
if (_connection != null)
{
if (_connection.IsOpen())

Loading…
Cancel
Save