prioritize newly created accounts in sync + test
This commit is contained in:
parent
1855830703
commit
f6b0c13ce8
2 changed files with 35 additions and 1 deletions
|
@ -88,7 +88,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
|||
|
||||
public async Task<SyncTwitterUser[]> 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)
|
||||
{
|
||||
|
|
|
@ -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 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
|||
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()
|
||||
{
|
||||
|
|
Reference in a new issue