mirror of https://github.com/Sonarr/Sonarr
fixed marr threading bug.
datamapper instances should not be reused!!!
This commit is contained in:
parent
440a128f28
commit
28a919e74a
|
@ -18,7 +18,7 @@ namespace NzbDrone.Core.Test.Datastore
|
||||||
public void SingleOrDefault_should_return_null_on_empty_db()
|
public void SingleOrDefault_should_return_null_on_empty_db()
|
||||||
{
|
{
|
||||||
Mocker.Resolve<IDatabase>()
|
Mocker.Resolve<IDatabase>()
|
||||||
.DataMapper.Query<Series>()
|
.GetDataMapper().Query<Series>()
|
||||||
.SingleOrDefault(c => c.CleanTitle == "SomeTitle")
|
.SingleOrDefault(c => c.CleanTitle == "SomeTitle")
|
||||||
.Should()
|
.Should()
|
||||||
.BeNull();
|
.BeNull();
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Datastore
|
||||||
|
|
||||||
private IDataMapper DataMapper
|
private IDataMapper DataMapper
|
||||||
{
|
{
|
||||||
get { return _database.DataMapper; }
|
get { return _database.GetDataMapper(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicRepository(IDatabase database, IMessageAggregator messageAggregator)
|
public BasicRepository(IDatabase database, IMessageAggregator messageAggregator)
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
public interface IDatabase
|
public interface IDatabase
|
||||||
{
|
{
|
||||||
IDataMapper DataMapper { get; }
|
IDataMapper GetDataMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Database : IDatabase
|
public class Database : IDatabase
|
||||||
|
@ -17,12 +17,9 @@ namespace NzbDrone.Core.Datastore
|
||||||
_dataMapperFactory = dataMapperFactory;
|
_dataMapperFactory = dataMapperFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDataMapper DataMapper
|
public IDataMapper GetDataMapper()
|
||||||
{
|
{
|
||||||
get
|
return _dataMapperFactory();
|
||||||
{
|
|
||||||
return _dataMapperFactory();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Marr.Data;
|
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
|
||||||
namespace NzbDrone.Core.SeriesStats
|
namespace NzbDrone.Core.SeriesStats
|
||||||
|
@ -12,18 +11,20 @@ namespace NzbDrone.Core.SeriesStats
|
||||||
|
|
||||||
public class SeriesStatisticsRepository : ISeriesStatisticsRepository
|
public class SeriesStatisticsRepository : ISeriesStatisticsRepository
|
||||||
{
|
{
|
||||||
private readonly IDataMapper _dataMapper;
|
private readonly IDatabase _database;
|
||||||
|
|
||||||
public SeriesStatisticsRepository(IDatabase database)
|
public SeriesStatisticsRepository(IDatabase database)
|
||||||
{
|
{
|
||||||
_dataMapper = database.DataMapper;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SeriesStatistics> SeriesStatistics()
|
public List<SeriesStatistics> SeriesStatistics()
|
||||||
{
|
{
|
||||||
_dataMapper.AddParameter("currentDate", DateTime.UtcNow);
|
var mapper = _database.GetDataMapper();
|
||||||
|
|
||||||
var queryText = @"SELECT
|
mapper.AddParameter("currentDate", DateTime.UtcNow);
|
||||||
|
|
||||||
|
const string queryText = @"SELECT
|
||||||
SeriesId,
|
SeriesId,
|
||||||
SUM(CASE WHEN Monitored = 1 AND Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
|
SUM(CASE WHEN Monitored = 1 AND Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
|
||||||
SUM(CASE WHEN Monitored = 1 AND Episodes.EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) as EpisodeFileCount,
|
SUM(CASE WHEN Monitored = 1 AND Episodes.EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) as EpisodeFileCount,
|
||||||
|
@ -32,7 +33,7 @@ namespace NzbDrone.Core.SeriesStats
|
||||||
FROM Episodes
|
FROM Episodes
|
||||||
GROUP BY SeriesId";
|
GROUP BY SeriesId";
|
||||||
|
|
||||||
return _dataMapper.Query<SeriesStatistics>(queryText);
|
return mapper.Query<SeriesStatistics>(queryText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,12 @@ namespace NzbDrone.Core.Tv
|
||||||
|
|
||||||
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
|
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
|
||||||
{
|
{
|
||||||
private readonly IDataMapper _dataMapper;
|
private readonly IDatabase _database;
|
||||||
|
|
||||||
public EpisodeRepository(IDatabase database, IMessageAggregator messageAggregator)
|
public EpisodeRepository(IDatabase database, IMessageAggregator messageAggregator)
|
||||||
: base(database, messageAggregator)
|
: base(database, messageAggregator)
|
||||||
{
|
{
|
||||||
_dataMapper = database.DataMapper;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Episode Get(int seriesId, int season, int episodeNumber)
|
public Episode Get(int seriesId, int season, int episodeNumber)
|
||||||
|
@ -135,16 +135,18 @@ namespace NzbDrone.Core.Tv
|
||||||
|
|
||||||
public void SetMonitoredBySeason(int seriesId, int seasonNumber, bool monitored)
|
public void SetMonitoredBySeason(int seriesId, int seasonNumber, bool monitored)
|
||||||
{
|
{
|
||||||
_dataMapper.AddParameter("seriesId", seriesId);
|
var mapper = _database.GetDataMapper();
|
||||||
_dataMapper.AddParameter("seasonNumber", seasonNumber);
|
|
||||||
_dataMapper.AddParameter("monitored", monitored);
|
|
||||||
|
|
||||||
var sql = "UPDATE Episodes " +
|
mapper.AddParameter("seriesId", seriesId);
|
||||||
"SET Monitored = @monitored " +
|
mapper.AddParameter("seasonNumber", seasonNumber);
|
||||||
"WHERE SeriesId = @seriesId " +
|
mapper.AddParameter("monitored", monitored);
|
||||||
"AND SeasonNumber = @seasonNumber";
|
|
||||||
|
|
||||||
_dataMapper.ExecuteNonQuery(sql);
|
const string sql = "UPDATE Episodes " +
|
||||||
|
"SET Monitored = @monitored " +
|
||||||
|
"WHERE SeriesId = @seriesId " +
|
||||||
|
"AND SeasonNumber = @seasonNumber";
|
||||||
|
|
||||||
|
mapper.ExecuteNonQuery(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFileId(int episodeId, int fileId)
|
public void SetFileId(int episodeId, int fileId)
|
||||||
|
|
Loading…
Reference in New Issue