Browse Source

save last sync

master
Nicolas Constant 2 years ago
parent
commit
b4c01ad326
No known key found for this signature in database GPG Key ID: 1E9F677FB01A5688
8 changed files with 25 additions and 18 deletions
  1. +1
    -1
      src/BirdsiteLive/Services/FederationService.cs
  2. +5
    -4
      src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs
  3. +3
    -2
      src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs
  4. +2
    -2
      src/DataAccessLayers/BirdsiteLive.DAL/DatabaseInitializer.cs
  5. +2
    -1
      src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/CachedTweetsPostgresDalTests.cs
  6. +2
    -1
      src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs
  7. +5
    -2
      src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs
  8. +5
    -5
      src/Tests/BirdsiteLive.DAL.Tests/DatabaseInitializerTests.cs

+ 1
- 1
src/BirdsiteLive/Services/FederationService.cs View File

@ -24,7 +24,7 @@ namespace BirdsiteLive.Services
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _databaseInitializer.DbInitAsync();
await _databaseInitializer.InitAndMigrateDbAsync();
await _statusPublicationPipeline.ExecuteAsync(stoppingToken);
}
}

+ 5
- 4
src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs View File

@ -75,19 +75,20 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
}
}
public async Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId)
public async Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId, DateTime lastSync)
{
if(id == default) throw new ArgumentException("id");
if(lastTweetPostedId == default) throw new ArgumentException("lastTweetPostedId");
if(lastTweetSynchronizedForAllFollowersId == default) throw new ArgumentException("lastTweetSynchronizedForAllFollowersId");
var query = $"UPDATE {_settings.TwitterUserTableName} SET lastTweetPostedId = @lastTweetPostedId, lastTweetSynchronizedForAllFollowersId = @lastTweetSynchronizedForAllFollowersId WHERE id = @id";
if(lastSync == default) throw new ArgumentException("lastSync");
var query = $"UPDATE {_settings.TwitterUserTableName} SET lastTweetPostedId = @lastTweetPostedId, lastTweetSynchronizedForAllFollowersId = @lastTweetSynchronizedForAllFollowersId, lastSync = @lastSync WHERE id = @id";
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { id, lastTweetPostedId, lastTweetSynchronizedForAllFollowersId });
await dbConnection.QueryAsync(query, new { id, lastTweetPostedId, lastTweetSynchronizedForAllFollowersId, lastSync = lastSync.ToUniversalTime() });
}
}


+ 3
- 2
src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs View File

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using BirdsiteLive.DAL.Models;
namespace BirdsiteLive.DAL.Contracts
@ -8,7 +9,7 @@ namespace BirdsiteLive.DAL.Contracts
Task CreateTwitterUserAsync(string acct, long lastTweetPostedId);
Task<SyncTwitterUser> GetTwitterUserAsync(string acct);
Task<SyncTwitterUser[]> GetAllTwitterUsersAsync();
Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId);
Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId, DateTime lastSync);
Task DeleteTwitterUserAsync(string acct);
Task<int> GetTwitterUsersCountAsync();
}

+ 2
- 2
src/DataAccessLayers/BirdsiteLive.DAL/DatabaseInitializer.cs View File

@ -7,7 +7,7 @@ namespace BirdsiteLive.DAL
{
public interface IDatabaseInitializer
{
Task DbInitAsync();
Task InitAndMigrateDbAsync();
}
public class DatabaseInitializer : IDatabaseInitializer
@ -21,7 +21,7 @@ namespace BirdsiteLive.DAL
}
#endregion
public async Task DbInitAsync()
public async Task InitAndMigrateDbAsync()
{
var currentVersion = await _dbInitializerDal.GetCurrentDbVersionAsync();
var mandatoryVersion = _dbInitializerDal.GetMandatoryDbVersion();


+ 2
- 1
src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/CachedTweetsPostgresDalTests.cs View File

@ -14,7 +14,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
public async Task TestInit()
{
var dal = new DbInitializerPostgresDal(_settings, _tools);
await dal.InitDbAsync();
var init = new DatabaseInitializer(dal);
await init.InitAndMigrateDbAsync();
}
[TestCleanup]


+ 2
- 1
src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/FollowersPostgresDalTests.cs View File

@ -16,7 +16,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
public async Task TestInit()
{
var dal = new DbInitializerPostgresDal(_settings, _tools);
await dal.InitDbAsync();
var init = new DatabaseInitializer(dal);
await init.InitAndMigrateDbAsync();
}
[TestCleanup]


+ 5
- 2
src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs View File

@ -14,7 +14,8 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
public async Task TestInit()
{
var dal = new DbInitializerPostgresDal(_settings, _tools);
await dal.InitDbAsync();
var init = new DatabaseInitializer(dal);
await init.InitAndMigrateDbAsync();
}
[TestCleanup]
@ -70,13 +71,15 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
var updatedLastTweetId = 1600L;
var updatedLastSyncId = 1550L;
await dal.UpdateTwitterUserAsync(result.Id, updatedLastTweetId, updatedLastSyncId);
var now = DateTime.Now;
await dal.UpdateTwitterUserAsync(result.Id, updatedLastTweetId, updatedLastSyncId, now);
result = await dal.GetTwitterUserAsync(acct);
Assert.AreEqual(acct, result.Acct);
Assert.AreEqual(updatedLastTweetId, result.LastTweetPostedId);
Assert.AreEqual(updatedLastSyncId, result.LastTweetSynchronizedForAllFollowersId);
Assert.IsTrue(Math.Abs((now.ToUniversalTime() - result.LastSync).Milliseconds) < 100);
}
[TestMethod]


+ 5
- 5
src/Tests/BirdsiteLive.DAL.Tests/DatabaseInitializerTests.cs View File

@ -31,7 +31,7 @@ namespace BirdsiteLive.DAL.Tests
#endregion
var dbInitializer = new DatabaseInitializer(dbInitializerDal.Object);
await dbInitializer.DbInitAsync();
await dbInitializer.InitAndMigrateDbAsync();
#region Validations
dbInitializerDal.VerifyAll();
@ -69,7 +69,7 @@ namespace BirdsiteLive.DAL.Tests
#endregion
var dbInitializer = new DatabaseInitializer(dbInitializerDal.Object);
await dbInitializer.DbInitAsync();
await dbInitializer.InitAndMigrateDbAsync();
#region Validations
dbInitializerDal.VerifyAll();
@ -122,7 +122,7 @@ namespace BirdsiteLive.DAL.Tests
#endregion
var dbInitializer = new DatabaseInitializer(dbInitializerDal.Object);
await dbInitializer.DbInitAsync();
await dbInitializer.InitAndMigrateDbAsync();
#region Validations
dbInitializerDal.VerifyAll();
@ -171,7 +171,7 @@ namespace BirdsiteLive.DAL.Tests
#endregion
var dbInitializer = new DatabaseInitializer(dbInitializerDal.Object);
await dbInitializer.DbInitAsync();
await dbInitializer.InitAndMigrateDbAsync();
#region Validations
dbInitializerDal.VerifyAll();
@ -227,7 +227,7 @@ namespace BirdsiteLive.DAL.Tests
var dbInitializer = new DatabaseInitializer(dbInitializerDal.Object);
try
{
await dbInitializer.DbInitAsync();
await dbInitializer.InitAndMigrateDbAsync();
}
finally
{


Loading…
Cancel
Save