diff --git a/src/BirdsiteLive/Controllers/StatisticsController.cs b/src/BirdsiteLive/Controllers/StatisticsController.cs index 2252274..4078a31 100644 --- a/src/BirdsiteLive/Controllers/StatisticsController.cs +++ b/src/BirdsiteLive/Controllers/StatisticsController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using BirdsiteLive.DAL.Contracts; using BirdsiteLive.Domain.Statistics; @@ -16,7 +17,6 @@ namespace BirdsiteLive.Controllers private readonly ITwitterStatisticsHandler _twitterStatistics; private readonly IExtractionStatisticsHandler _extractionStatistics; - #region Ctor public StatisticsController(ITwitterUserDal twitterUserDal, IFollowersDal followersDal, ITwitterStatisticsHandler twitterStatistics, IExtractionStatisticsHandler extractionStatistics) { @@ -34,6 +34,7 @@ namespace BirdsiteLive.Controllers FollowersCount = await _followersDal.GetFollowersCountAsync(), FailingFollowersCount = await _followersDal.GetFailingFollowersCountAsync(), TwitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync(), + FailingTwitterUserCount = await _twitterUserDal.GetFailingTwitterUsersCountAsync(), TwitterStatistics = _twitterStatistics.GetStatistics(), ExtractionStatistics = _extractionStatistics.GetStatistics(), }; diff --git a/src/BirdsiteLive/Models/StatisticsModels/Statistics.cs b/src/BirdsiteLive/Models/StatisticsModels/Statistics.cs index 8cb2adf..4a66f81 100644 --- a/src/BirdsiteLive/Models/StatisticsModels/Statistics.cs +++ b/src/BirdsiteLive/Models/StatisticsModels/Statistics.cs @@ -8,8 +8,8 @@ namespace BirdsiteLive.Models.StatisticsModels public int FollowersCount { get; set; } public int FailingFollowersCount { get; set; } public int TwitterUserCount { get; set; } + public int FailingTwitterUserCount { get; set; } public ApiStatistics TwitterStatistics { get; set; } public ExtractionStatistics ExtractionStatistics { get; set; } - } } \ No newline at end of file diff --git a/src/BirdsiteLive/Views/Statistics/Index.cshtml b/src/BirdsiteLive/Views/Statistics/Index.cshtml index 25a0795..4382e2a 100644 --- a/src/BirdsiteLive/Views/Statistics/Index.cshtml +++ b/src/BirdsiteLive/Views/Statistics/Index.cshtml @@ -9,6 +9,7 @@

Instance

diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs index 506848c..48b8455 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs @@ -73,6 +73,19 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers } } + public async Task GetFailingTwitterUsersCountAsync() + { + var query = $"SELECT COUNT(*) FROM {_settings.TwitterUserTableName} WHERE fetchingErrorCount > 0"; + + using (var dbConnection = Connection) + { + dbConnection.Open(); + + var result = (await dbConnection.QueryAsync(query)).FirstOrDefault(); + return result; + } + } + public async Task GetAllTwitterUsersAsync(int maxNumber) { var query = $"SELECT * FROM {_settings.TwitterUserTableName} ORDER BY lastSync ASC LIMIT @maxNumber"; diff --git a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs index eb6602f..ef2cc36 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs @@ -16,5 +16,6 @@ namespace BirdsiteLive.DAL.Contracts Task DeleteTwitterUserAsync(string acct); Task DeleteTwitterUserAsync(int id); Task GetTwitterUsersCountAsync(); + Task GetFailingTwitterUsersCountAsync(); } } \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs index 3a742c8..68a060f 100644 --- a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs +++ b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs @@ -301,5 +301,27 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers var result = await dal.GetTwitterUsersCountAsync(); Assert.AreEqual(10, result); } + + [TestMethod] + public async Task CountFailingTwitterUsers() + { + var dal = new TwitterUserPostgresDal(_settings); + for (var i = 0; i < 10; i++) + { + var acct = $"myid{i}"; + var lastTweetId = 1548L; + + await dal.CreateTwitterUserAsync(acct, lastTweetId); + + if (i == 0 || i == 2 || i == 3) + { + var t = await dal.GetTwitterUserAsync(acct); + await dal.UpdateTwitterUserAsync(t.Id ,1L,2L, 50+i*2, DateTime.Now); + } + } + + var result = await dal.GetFailingTwitterUsersCountAsync(); + Assert.AreEqual(3, result); + } } } \ No newline at end of file