diff --git a/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs b/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs
index dae9fe0..3a36be3 100644
--- a/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs
+++ b/src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
@@ -57,6 +58,7 @@ private async Task AnalyseFailingUserAsync(SyncTwitterUser user)
{
var dbUser = await _twitterUserDal.GetTwitterUserAsync(user.Acct);
dbUser.FetchingErrorCount++;
+ dbUser.LastSync = DateTime.UtcNow;
if (dbUser.FetchingErrorCount > _instanceSettings.FailingTwitterUserCleanUpThreshold)
{
diff --git a/src/BirdsiteLive/BirdsiteLive.csproj b/src/BirdsiteLive/BirdsiteLive.csproj
index 25ea8a9..a30e4e0 100644
--- a/src/BirdsiteLive/BirdsiteLive.csproj
+++ b/src/BirdsiteLive/BirdsiteLive.csproj
@@ -4,7 +4,7 @@
netcoreapp3.1
d21486de-a812-47eb-a419-05682bb68856
Linux
- 0.19.0
+ 0.19.1
diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs
index 48b8455..11214d4 100644
--- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs
+++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs
@@ -88,7 +88,7 @@ public async Task GetFailingTwitterUsersCountAsync()
public async Task GetAllTwitterUsersAsync(int maxNumber)
{
- var query = $"SELECT * FROM {_settings.TwitterUserTableName} ORDER BY lastSync ASC LIMIT @maxNumber";
+ var query = $"SELECT * FROM {_settings.TwitterUserTableName} ORDER BY lastSync ASC NULLS FIRST LIMIT @maxNumber";
using (var dbConnection = Connection)
{
diff --git a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs
index 68a060f..0b007b6 100644
--- a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs
+++ b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
+using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
@@ -231,6 +232,39 @@ public async Task GetAllTwitterUsers_Top()
Assert.IsFalse(result[0].LastTweetSynchronizedForAllFollowersId == default);
}
+ [TestMethod]
+ public async Task GetAllTwitterUsers_Top_NotInit()
+ {
+ // Create accounts
+ var dal = new TwitterUserPostgresDal(_settings);
+ for (var i = 0; i < 1000; i++)
+ {
+ var acct = $"myid{i}";
+ var lastTweetId = i+10;
+
+ await dal.CreateTwitterUserAsync(acct, lastTweetId);
+ }
+
+ // Update accounts
+ var now = DateTime.UtcNow;
+ var allUsers = await dal.GetAllTwitterUsersAsync();
+ foreach (var acc in allUsers)
+ {
+ var lastSync = now.AddDays(acc.LastTweetPostedId);
+ acc.LastSync = lastSync;
+ await dal.UpdateTwitterUserAsync(acc);
+ }
+
+ // Create a not init account
+ await dal.CreateTwitterUserAsync("not_init", -1);
+
+ var result = await dal.GetAllTwitterUsersAsync(10);
+
+ Assert.IsTrue(result.Any(x => x.Acct == "myid0"));
+ Assert.IsTrue(result.Any(x => x.Acct == "myid8"));
+ Assert.IsTrue(result.Any(x => x.Acct == "not_init"));
+ }
+
[TestMethod]
public async Task GetAllTwitterUsers_Limited()
{
diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs
index 52ace24..d5fbeef 100644
--- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs
+++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs
@@ -329,5 +329,64 @@ public async Task ProcessAsync_Protected_Test()
removeTwitterAccountActionMock.VerifyAll();
#endregion
}
+
+ [TestMethod]
+ public async Task ProcessAsync_Unfound_NotInit_Test()
+ {
+ #region Stubs
+ var userId1 = 1;
+ var acct1 = "user1";
+
+ var users = new List
+ {
+ new SyncTwitterUser
+ {
+ Id = userId1,
+ Acct = acct1,
+ LastSync = default,
+ LastTweetPostedId = -1,
+ LastTweetSynchronizedForAllFollowersId = -1
+ }
+ };
+
+ var settings = new InstanceSettings
+ {
+ FailingTwitterUserCleanUpThreshold = 300
+ };
+ #endregion
+
+ #region Mocks
+ var twitterUserServiceMock = new Mock(MockBehavior.Strict);
+ twitterUserServiceMock
+ .Setup(x => x.GetUser(It.Is(y => y == acct1)))
+ .Returns((TwitterUser)null);
+
+ twitterUserServiceMock
+ .Setup(x => x.PurgeUser(It.Is(y => y == acct1)));
+
+ var twitterUserDalMock = new Mock(MockBehavior.Strict);
+ twitterUserDalMock
+ .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct1)))
+ .ReturnsAsync(users.First());
+
+ twitterUserDalMock
+ .Setup(x => x.UpdateTwitterUserAsync(
+ It.Is(y => y.Id == userId1 && y.FetchingErrorCount == 1 && y.LastSync != default)))
+ .Returns(Task.CompletedTask);
+
+ var removeTwitterAccountActionMock = new Mock(MockBehavior.Strict);
+ #endregion
+
+ var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings);
+ var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None);
+
+ #region Validations
+ Assert.AreEqual(0, result.Length);
+
+ twitterUserServiceMock.VerifyAll();
+ twitterUserDalMock.VerifyAll();
+ removeTwitterAccountActionMock.VerifyAll();
+ #endregion
+ }
}
}
\ No newline at end of file