Merge pull request #119 from NicolasConstant/topic_remove-failing-follower

Topic remove failing follower
This commit is contained in:
Nicolas Constant 2021-09-11 19:23:53 -04:00 committed by GitHub
commit 567453a0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 1 deletions

View file

@ -32,6 +32,7 @@ namespace BirdsiteLive.Controllers
var stats = new Models.StatisticsModels.Statistics
{
FollowersCount = await _followersDal.GetFollowersCountAsync(),
FailingFollowersCount = await _followersDal.GetFailingFollowersCountAsync(),
TwitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync(),
TwitterStatistics = _twitterStatistics.GetStatistics(),
ExtractionStatistics = _extractionStatistics.GetStatistics(),

View file

@ -6,8 +6,10 @@ namespace BirdsiteLive.Models.StatisticsModels
public class Statistics
{
public int FollowersCount { get; set; }
public int FailingFollowersCount { get; set; }
public int TwitterUserCount { get; set; }
public ApiStatistics TwitterStatistics { get; set; }
public ExtractionStatistics ExtractionStatistics { get; set; }
}
}

View file

@ -10,6 +10,7 @@
<ul>
<li>Twitter Users: @Model.TwitterUserCount</li>
<li>Followers: @Model.FollowersCount</li>
<li>Failing Followers: @Model.FailingFollowersCount</li>
</ul>
<h4>Twitter API (Min, Avg, Max for the last 24h)</h4>

View file

@ -53,6 +53,19 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
}
}
public async Task<int> GetFailingFollowersCountAsync()
{
var query = $"SELECT COUNT(*) FROM {_settings.FollowersTableName} WHERE postingErrorCount > 0";
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<int>(query)).FirstOrDefault();
return result;
}
}
public async Task<Follower> GetFollowerAsync(string acct, string host)
{
var query = $"SELECT * FROM {_settings.FollowersTableName} WHERE acct = @acct AND host = @host";

View file

@ -15,5 +15,6 @@ namespace BirdsiteLive.DAL.Contracts
Task DeleteFollowerAsync(int id);
Task DeleteFollowerAsync(string acct, string host);
Task<int> GetFollowersCountAsync();
Task<int> GetFailingFollowersCountAsync();
}
}

View file

@ -237,7 +237,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
actorId = $"https://{host}/{acct}";
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
//User 2
//User 3
acct = "myhandle3";
host = "domain.ext";
following = new[] { 1 };
@ -250,6 +250,54 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
Assert.AreEqual(3, result);
}
[TestMethod]
public async Task CountFailingFollowersAsync()
{
var dal = new FollowersPostgresDal(_settings);
var result = await dal.GetFailingFollowersCountAsync();
Assert.AreEqual(0, result);
//User 1
var acct = "myhandle1";
var host = "domain.ext";
var following = new[] { 1, 2, 3 };
var followingSync = new Dictionary<int, long>();
var inboxRoute = "/myhandle1/inbox";
var sharedInboxRoute = "/inbox";
var actorId = $"https://{host}/{acct}";
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
//User 2
acct = "myhandle2";
host = "domain.ext";
following = new[] { 2, 4, 5 };
inboxRoute = "/myhandle2/inbox";
sharedInboxRoute = "/inbox2";
actorId = $"https://{host}/{acct}";
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
var follower = await dal.GetFollowerAsync(acct, host);
follower.PostingErrorCount = 1;
await dal.UpdateFollowerAsync(follower);
//User 3
acct = "myhandle3";
host = "domain.ext";
following = new[] { 1 };
inboxRoute = "/myhandle3/inbox";
sharedInboxRoute = "/inbox3";
actorId = $"https://{host}/{acct}";
await dal.CreateFollowerAsync(acct, host, inboxRoute, sharedInboxRoute, actorId, following, followingSync);
follower = await dal.GetFollowerAsync(acct, host);
follower.PostingErrorCount = 50;
await dal.UpdateFollowerAsync(follower);
result = await dal.GetFailingFollowersCountAsync();
Assert.AreEqual(2, result);
}
[TestMethod]
public async Task CreateUpdateAndGetFollower_Add()
{