From cffc1db3e63594e5a6ba7acf8690705098ee7882 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Fri, 13 Jan 2023 10:59:36 -0500 Subject: [PATCH] stats in about page --- .../Services/CachedStatisticsService.cs | 11 +++++++++-- src/BirdsiteLive/Views/About/Index.cshtml | 19 ++----------------- .../TwitterUserPostgresDal.cs | 2 +- .../TwitterUserPostgresDalTests.cs | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/BirdsiteLive/Services/CachedStatisticsService.cs b/src/BirdsiteLive/Services/CachedStatisticsService.cs index bc2235d..ef3d4e8 100644 --- a/src/BirdsiteLive/Services/CachedStatisticsService.cs +++ b/src/BirdsiteLive/Services/CachedStatisticsService.cs @@ -13,15 +13,17 @@ namespace BirdsiteLive.Services public class CachedStatisticsService : ICachedStatisticsService { private readonly ITwitterUserDal _twitterUserDal; + private readonly IFollowersDal _followersDal; private static CachedStatistics _cachedStatistics; private readonly InstanceSettings _instanceSettings; #region Ctor - public CachedStatisticsService(ITwitterUserDal twitterUserDal, InstanceSettings instanceSettings) + public CachedStatisticsService(ITwitterUserDal twitterUserDal, IFollowersDal followersDal, InstanceSettings instanceSettings) { _twitterUserDal = twitterUserDal; _instanceSettings = instanceSettings; + _followersDal = followersDal; } #endregion @@ -34,12 +36,15 @@ namespace BirdsiteLive.Services 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 + SyncLag = twitterSyncLag, + TwitterUsers = twitterUserCount, + FediverseUsers = fediverseUsers }; } @@ -52,5 +57,7 @@ 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; } } } \ No newline at end of file diff --git a/src/BirdsiteLive/Views/About/Index.cshtml b/src/BirdsiteLive/Views/About/Index.cshtml index 1f16b09..a86f4f6 100644 --- a/src/BirdsiteLive/Views/About/Index.cshtml +++ b/src/BirdsiteLive/Views/About/Index.cshtml @@ -4,27 +4,12 @@ }
-

Node Saturation

+

Service load


- This node usage is at @Model.Saturation%
+ There are @Model.FediverseUsers fediverse users following @Model.TwitterUsers twitter users

-

FAQ

-

Why is there a limit on the node?

- -

BirdsiteLIVE rely on the Twitter API to provide high quality content. This API has limitations and therefore limits node capacity.

- -

What happen when the node is saturated?

- -

- When the saturation rate goes above 100% the node will no longer update all accounts every 15 minutes and instead will reduce the pooling rate to stay under the API limits, the more saturated a node is the less efficient it will be.
- The software doesn't scale, and it's by design. -

- -

How can I reduce the node's saturation?

- -

If you're not on your own node, be reasonable and don't follow too much accounts. And if you can, host your own node. BirdsiteLIVE doesn't require a lot of resources to work and therefore is really cheap to self-host.

\ No newline at end of file diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs index 07bad2a..8b06e85 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs @@ -98,7 +98,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers public async Task GetTwitterUsersCountAsync() { - var query = $"SELECT COUNT(*) FROM {_settings.TwitterUserTableName}"; + var query = $"SELECT COUNT(*) FROM (SELECT unnest(followings) as follow FROM {_settings.FollowersTableName} GROUP BY follow) AS f INNER JOIN {_settings.TwitterUserTableName} ON f.follow={_settings.TwitterUserTableName}.id"; 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 c9bc746..d5422ce 100644 --- a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs +++ b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs @@ -365,7 +365,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers } var result = await dal.GetTwitterUsersCountAsync(); - Assert.AreEqual(10, result); + Assert.AreEqual(0, result); } [TestMethod]