stats in about page

This commit is contained in:
Vincent Cloutier 2023-01-13 10:59:36 -05:00
parent b5777d656e
commit cffc1db3e6
4 changed files with 13 additions and 21 deletions

View file

@ -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; }
}
}

View file

@ -4,27 +4,12 @@
}
<div class="col-12 col-sm-12 col-md-10 col-lg-8 mx-auto">
<h2>Node Saturation</h2>
<h2>Service load</h2>
<p>
<br/>
This node usage is at @Model.Saturation%<br/>
There are @Model.FediverseUsers fediverse users following @Model.TwitterUsers twitter users<br/>
<br/>
</p>
<h2>FAQ</h2>
<h4>Why is there a limit on the node?</h4>
<p>BirdsiteLIVE rely on the Twitter API to provide high quality content. This API has limitations and therefore limits node capacity.</p>
<h4>What happen when the node is saturated?</h4>
<p>
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.<br />
The software doesn't scale, and it's by design.
</p>
<h4>How can I reduce the node's saturation?</h4>
<p>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.</p>
</div>

View file

@ -98,7 +98,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
public async Task<int> 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)
{

View file

@ -365,7 +365,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
}
var result = await dal.GetTwitterUsersCountAsync();
Assert.AreEqual(10, result);
Assert.AreEqual(0, result);
}
[TestMethod]