fixed marr threading bug.

datamapper instances should not be reused!!!
pull/24/head
Keivan Beigi 11 years ago
parent 440a128f28
commit 28a919e74a

@ -18,7 +18,7 @@ namespace NzbDrone.Core.Test.Datastore
public void SingleOrDefault_should_return_null_on_empty_db()
{
Mocker.Resolve<IDatabase>()
.DataMapper.Query<Series>()
.GetDataMapper().Query<Series>()
.SingleOrDefault(c => c.CleanTitle == "SomeTitle")
.Should()
.BeNull();

@ -43,7 +43,7 @@ namespace NzbDrone.Core.Datastore
private IDataMapper DataMapper
{
get { return _database.DataMapper; }
get { return _database.GetDataMapper(); }
}
public BasicRepository(IDatabase database, IMessageAggregator messageAggregator)

@ -5,7 +5,7 @@ namespace NzbDrone.Core.Datastore
{
public interface IDatabase
{
IDataMapper DataMapper { get; }
IDataMapper GetDataMapper();
}
public class Database : IDatabase
@ -17,12 +17,9 @@ namespace NzbDrone.Core.Datastore
_dataMapperFactory = dataMapperFactory;
}
public IDataMapper DataMapper
public IDataMapper GetDataMapper()
{
get
{
return _dataMapperFactory();
}
return _dataMapperFactory();
}
}
}

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Marr.Data;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.SeriesStats
@ -12,18 +11,20 @@ namespace NzbDrone.Core.SeriesStats
public class SeriesStatisticsRepository : ISeriesStatisticsRepository
{
private readonly IDataMapper _dataMapper;
private readonly IDatabase _database;
public SeriesStatisticsRepository(IDatabase database)
{
_dataMapper = database.DataMapper;
_database = database;
}
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,
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,
@ -32,7 +33,7 @@ namespace NzbDrone.Core.SeriesStats
FROM Episodes
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
{
private readonly IDataMapper _dataMapper;
private readonly IDatabase _database;
public EpisodeRepository(IDatabase database, IMessageAggregator messageAggregator)
: base(database, messageAggregator)
{
_dataMapper = database.DataMapper;
_database = database;
}
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)
{
_dataMapper.AddParameter("seriesId", seriesId);
_dataMapper.AddParameter("seasonNumber", seasonNumber);
_dataMapper.AddParameter("monitored", monitored);
var mapper = _database.GetDataMapper();
var sql = "UPDATE Episodes " +
"SET Monitored = @monitored " +
"WHERE SeriesId = @seriesId " +
"AND SeasonNumber = @seasonNumber";
mapper.AddParameter("seriesId", seriesId);
mapper.AddParameter("seasonNumber", seasonNumber);
mapper.AddParameter("monitored", monitored);
_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)

Loading…
Cancel
Save