added failing follower count in DAL

This commit is contained in:
Nicolas Constant 2021-09-11 19:16:52 -04:00
parent 18d2096dc3
commit 98e869f064
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 63 additions and 1 deletions

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()
{