prioritize newly created accounts in sync + test

This commit is contained in:
Nicolas Constant 2021-11-20 16:03:27 -05:00
parent 1855830703
commit f6b0c13ce8
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
2 changed files with 35 additions and 1 deletions

View file

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

View file

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