diff --git a/src/BirdsiteLive.Common/Settings/InstanceSettings.cs b/src/BirdsiteLive.Common/Settings/InstanceSettings.cs index 0f701ff..89b535b 100644 --- a/src/BirdsiteLive.Common/Settings/InstanceSettings.cs +++ b/src/BirdsiteLive.Common/Settings/InstanceSettings.cs @@ -7,7 +7,6 @@ public string AdminEmail { get; set; } public bool ResolveMentionsInProfiles { get; set; } public bool PublishReplies { get; set; } - public int MaxUsersCapacity { get; set; } public string UnlistedTwitterAccounts { get; set; } public string SensitiveTwitterAccounts { get; set; } diff --git a/src/BirdsiteLive.Pipeline/Processors/RetrieveTwitterUsersProcessor.cs b/src/BirdsiteLive.Pipeline/Processors/RetrieveTwitterUsersProcessor.cs index 8950c82..6224bb5 100644 --- a/src/BirdsiteLive.Pipeline/Processors/RetrieveTwitterUsersProcessor.cs +++ b/src/BirdsiteLive.Pipeline/Processors/RetrieveTwitterUsersProcessor.cs @@ -8,7 +8,6 @@ using BirdsiteLive.Common.Settings; using BirdsiteLive.DAL.Contracts; using BirdsiteLive.Pipeline.Models; using BirdsiteLive.Pipeline.Contracts; -using BirdsiteLive.Pipeline.Tools; using Microsoft.Extensions.Logging; namespace BirdsiteLive.Pipeline.Processors @@ -16,17 +15,15 @@ namespace BirdsiteLive.Pipeline.Processors public class RetrieveTwitterUsersProcessor : IRetrieveTwitterUsersProcessor { private readonly ITwitterUserDal _twitterUserDal; - private readonly IMaxUsersNumberProvider _maxUsersNumberProvider; private readonly ILogger _logger; private static Random rng = new Random(); public int WaitFactor = 1000 * 60; //1 min #region Ctor - public RetrieveTwitterUsersProcessor(ITwitterUserDal twitterUserDal, IMaxUsersNumberProvider maxUsersNumberProvider, ILogger logger) + public RetrieveTwitterUsersProcessor(ITwitterUserDal twitterUserDal, ILogger logger) { _twitterUserDal = twitterUserDal; - _maxUsersNumberProvider = maxUsersNumberProvider; _logger = logger; } #endregion diff --git a/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs b/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs deleted file mode 100644 index 1c7e7c4..0000000 --- a/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Threading.Tasks; -using BirdsiteLive.Common.Settings; -using BirdsiteLive.DAL.Contracts; - -namespace BirdsiteLive.Pipeline.Tools -{ - public interface IMaxUsersNumberProvider - { - Task GetMaxUsersNumberAsync(); - } - - public class MaxUsersNumberProvider : IMaxUsersNumberProvider - { - private readonly InstanceSettings _instanceSettings; - private readonly ITwitterUserDal _twitterUserDal; - - private int _totalUsersCount = -1; - private int _warmUpIterations; - private const int WarmUpMaxCapacity = 200; - - #region Ctor - public MaxUsersNumberProvider(InstanceSettings instanceSettings, ITwitterUserDal twitterUserDal) - { - _instanceSettings = instanceSettings; - _twitterUserDal = twitterUserDal; - } - #endregion - - public async Task GetMaxUsersNumberAsync() - { - // Init data - if (_totalUsersCount == -1) - { - _totalUsersCount = await _twitterUserDal.GetTwitterUsersCountAsync(); - _warmUpIterations = (int)(_totalUsersCount / (float)WarmUpMaxCapacity); - } - - // Return if warm up ended - if (_warmUpIterations <= 0) return _instanceSettings.MaxUsersCapacity; - - // Calculate warm up value - var maxUsers = _warmUpIterations > 0 - ? WarmUpMaxCapacity - : _instanceSettings.MaxUsersCapacity; - _warmUpIterations--; - return maxUsers; - } - } -} \ No newline at end of file diff --git a/src/BirdsiteLive/Component/NodeInfoViewComponent.cs b/src/BirdsiteLive/Component/NodeInfoViewComponent.cs index 00c03f3..1f0a8c6 100644 --- a/src/BirdsiteLive/Component/NodeInfoViewComponent.cs +++ b/src/BirdsiteLive/Component/NodeInfoViewComponent.cs @@ -37,7 +37,6 @@ namespace BirdsiteLive.Component twitterAccountPolicy == ModerationTypeEnum.BlackListing, WhitelistingEnabled = followerPolicy == ModerationTypeEnum.WhiteListing || twitterAccountPolicy == ModerationTypeEnum.WhiteListing, - InstanceSaturation = statistics.Saturation, SyncLag = statistics.SyncLag }; diff --git a/src/BirdsiteLive/Services/CachedStatisticsService.cs b/src/BirdsiteLive/Services/CachedStatisticsService.cs index ef3d4e8..d6567c6 100644 --- a/src/BirdsiteLive/Services/CachedStatisticsService.cs +++ b/src/BirdsiteLive/Services/CachedStatisticsService.cs @@ -32,16 +32,13 @@ namespace BirdsiteLive.Services if (_cachedStatistics == null || (DateTime.UtcNow - _cachedStatistics.RefreshedTime).TotalMinutes > 15) { - var twitterUserMax = _instanceSettings.MaxUsersCapacity; var twitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync(); var twitterSyncLag = await _twitterUserDal.GetTwitterSyncLag(); - var saturation = (int)((double)twitterUserCount / twitterUserMax * 100); var fediverseUsers = await _followersDal.GetFollowersCountAsync(); _cachedStatistics = new CachedStatistics { RefreshedTime = DateTime.UtcNow, - Saturation = saturation, SyncLag = twitterSyncLag, TwitterUsers = twitterUserCount, FediverseUsers = fediverseUsers @@ -56,7 +53,6 @@ namespace BirdsiteLive.Services { public DateTime RefreshedTime { get; set; } public TimeSpan SyncLag { get; set; } - public int Saturation { get; set; } public int TwitterUsers { get; set; } public int FediverseUsers { get; set; } } diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs index 73397a8..244c85f 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs @@ -7,7 +7,6 @@ using BirdsiteLive.Common.Settings; using BirdsiteLive.DAL.Contracts; using BirdsiteLive.DAL.Models; using BirdsiteLive.Pipeline.Processors; -using BirdsiteLive.Pipeline.Tools; using BirdsiteLive.Pipeline.Models; using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -33,11 +32,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors #endregion #region Mocks - var maxUsersNumberProviderMock = new Mock(MockBehavior.Strict); - maxUsersNumberProviderMock - .Setup(x => x.GetMaxUsersNumberAsync()) - .ReturnsAsync(maxUsers); - var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetAllTwitterUsersWithFollowersAsync( @@ -47,7 +41,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); processor.WaitFactor = 10; var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None); @@ -75,11 +69,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors #endregion #region Mocks - var maxUsersNumberProviderMock = new Mock(MockBehavior.Strict); - maxUsersNumberProviderMock - .Setup(x => x.GetMaxUsersNumberAsync()) - .ReturnsAsync(maxUsers); - var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .SetupSequence(x => x.GetAllTwitterUsersWithFollowersAsync( @@ -93,7 +82,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); processor.WaitFactor = 2; var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None); @@ -121,11 +110,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors #endregion #region Mocks - var maxUsersNumberProviderMock = new Mock(MockBehavior.Strict); - maxUsersNumberProviderMock - .Setup(x => x.GetMaxUsersNumberAsync()) - .ReturnsAsync(maxUsers); - var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .SetupSequence(x => x.GetAllTwitterUsersWithFollowersAsync( @@ -139,7 +123,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); processor.WaitFactor = 2; var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None); @@ -163,10 +147,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors #endregion #region Mocks - var maxUsersNumberProviderMock = new Mock(MockBehavior.Strict); - maxUsersNumberProviderMock - .Setup(x => x.GetMaxUsersNumberAsync()) - .ReturnsAsync(maxUsers); var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock @@ -177,7 +157,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); processor.WaitFactor = 1; var t =processor.GetTwitterUsersAsync(buffer, CancellationToken.None); @@ -199,11 +179,6 @@ namespace BirdsiteLive.Pipeline.Tests.Processors #endregion #region Mocks - var maxUsersNumberProviderMock = new Mock(MockBehavior.Strict); - maxUsersNumberProviderMock - .Setup(x => x.GetMaxUsersNumberAsync()) - .ReturnsAsync(maxUsers); - var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetAllTwitterUsersWithFollowersAsync( @@ -213,7 +188,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); processor.WaitFactor = 10; var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None); @@ -238,17 +213,12 @@ namespace BirdsiteLive.Pipeline.Tests.Processors #endregion #region Mocks - var maxUsersNumberProviderMock = new Mock(MockBehavior.Strict); - maxUsersNumberProviderMock - .Setup(x => x.GetMaxUsersNumberAsync()) - .ReturnsAsync(maxUsers); - var twitterUserDalMock = new Mock(MockBehavior.Strict); var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); processor.WaitFactor = 1; await processor.GetTwitterUsersAsync(buffer, canTokenS.Token); } diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs deleted file mode 100644 index c2f52d0..0000000 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Threading.Tasks; -using BirdsiteLive.Common.Settings; -using BirdsiteLive.DAL.Contracts; -using BirdsiteLive.Pipeline.Tools; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace BirdsiteLive.Pipeline.Tests.Tools -{ - [TestClass] - public class MaxUsersNumberProviderTests - { - [TestMethod] - public async Task GetMaxUsersNumberAsync_WarmUp_Test() - { - #region Stubs - var settings = new InstanceSettings - { - MaxUsersCapacity = 1000 - }; - #endregion - - #region Mocks - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUsersCountAsync()) - .ReturnsAsync(1000); - #endregion - - var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object); - - var result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(200, result); - - result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(200, result); - - result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(200, result); - - result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(200, result); - - result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(200, result); - - result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(1000, result); - - #region Validations - twitterUserDalMock.VerifyAll(); - #endregion - } - - [TestMethod] - public async Task GetMaxUsersNumberAsync_NoWarmUp_Test() - { - #region Stubs - var settings = new InstanceSettings - { - MaxUsersCapacity = 1000 - }; - #endregion - - #region Mocks - var twitterUserDalMock = new Mock(MockBehavior.Strict); - twitterUserDalMock - .Setup(x => x.GetTwitterUsersCountAsync()) - .ReturnsAsync(199); - #endregion - - var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object); - - var result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(1000, result); - - #region Validations - twitterUserDalMock.VerifyAll(); - #endregion - } - } -} \ No newline at end of file