change stats on homepage

This commit is contained in:
Vincent Cloutier 2023-01-11 19:40:11 -05:00
parent 9026273f45
commit 83842f5874
5 changed files with 23 additions and 18 deletions

View file

@ -37,7 +37,8 @@ namespace BirdsiteLive.Component
twitterAccountPolicy == ModerationTypeEnum.BlackListing,
WhitelistingEnabled = followerPolicy == ModerationTypeEnum.WhiteListing ||
twitterAccountPolicy == ModerationTypeEnum.WhiteListing,
InstanceSaturation = statistics.Saturation
InstanceSaturation = statistics.Saturation,
SyncLag = statistics.SyncLag
};
//viewModel = new NodeInfoViewModel
@ -55,5 +56,6 @@ namespace BirdsiteLive.Component
public bool BlacklistingEnabled { get; set; }
public bool WhitelistingEnabled { get; set; }
public int InstanceSaturation { get; set; }
public TimeSpan SyncLag { get; set; }
}
}

View file

@ -32,12 +32,14 @@ namespace BirdsiteLive.Services
{
var twitterUserMax = _instanceSettings.MaxUsersCapacity;
var twitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync();
var twitterSyncLag = await _twitterUserDal.GetTwitterSyncLag();
var saturation = (int)((double)twitterUserCount / twitterUserMax * 100);
_cachedStatistics = new CachedStatistics
{
RefreshedTime = DateTime.UtcNow,
Saturation = saturation
Saturation = saturation,
SyncLag = twitterSyncLag
};
}
@ -48,6 +50,7 @@ namespace BirdsiteLive.Services
public class CachedStatistics
{
public DateTime RefreshedTime { get; set; }
public TimeSpan SyncLag { get; set; }
public int Saturation { get; set; }
}
}

View file

@ -1,22 +1,10 @@
@model BirdsiteLive.Component.NodeInfoViewModel
<div>
@if (ViewData.Model.WhitelistingEnabled)
{
<a asp-controller="About" asp-action="Whitelisting" class="badge badge-light" title="What does this mean?">Whitelisting Enabled</a>
}
@if (ViewData.Model.BlacklistingEnabled)
{
<a asp-controller="About" asp-action="Blacklisting" class="badge badge-light" title="What does this mean?">Blacklisting Enabled</a>
}
<div class="node-progress-bar">
<div class="node-progress-bar__label"><a asp-controller="About" asp-action="Index">Instance saturation:</a></div>
<div class="progress node-progress-bar__bar">
<div class="progress-bar
@((ViewData.Model.InstanceSaturation > 50 && ViewData.Model.InstanceSaturation < 75) ? "bg-warning ":"")
@((ViewData.Model.InstanceSaturation > 75 && ViewData.Model.InstanceSaturation < 100) ? "bg-danger ":"")
@((ViewData.Model.InstanceSaturation > 100) ? "bg-saturation-danger ":"")" style="width: @ViewData.Model.InstanceSaturation%">@ViewData.Model.InstanceSaturation%</div>
</div>
<div class="node-progress-bar__label">
<a asp-controller="About" asp-action="Index">Service load:</a>
@Math.Ceiling(ViewData.Model.SyncLag.TotalMinutes) minutes to fetch all twitter users
</div>
</div>
</div>

View file

@ -85,6 +85,17 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
};
}
public async Task<TimeSpan> GetTwitterSyncLag()
{
var query = $"SELECT max(lastsync) - min(lastsync) as diff FROM (SELECT unnest(followings) as follow FROM followers GROUP BY follow) AS f INNER JOIN twitter_users ON f.follow=twitter_users.id;";
using (var dbConnection = Connection)
{
var result = (await dbConnection.QueryAsync<TimeSpan>(query)).FirstOrDefault();
return result;
}
}
public async Task<int> GetTwitterUsersCountAsync()
{
var query = $"SELECT COUNT(*) FROM {_settings.TwitterUserTableName}";

View file

@ -18,6 +18,7 @@ namespace BirdsiteLive.DAL.Contracts
Task DeleteTwitterUserAsync(string acct);
Task DeleteTwitterUserAsync(int id);
Task<int> GetTwitterUsersCountAsync();
Task<TimeSpan> GetTwitterSyncLag();
Task<int> GetFailingTwitterUsersCountAsync();
}
}