displaying node infos

This commit is contained in:
Nicolas Constant 2021-02-24 00:27:16 -05:00
parent 7abc4a3b3e
commit 7503f34882
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
6 changed files with 152 additions and 58 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.Domain.Repository;
using BirdsiteLive.Services;
using BirdsiteLive.Statistics.Domain;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
@ -13,15 +14,13 @@ namespace BirdsiteLive.Component
public class NodeInfoViewComponent : ViewComponent
{
private readonly IModerationRepository _moderationRepository;
private readonly ITwitterStatisticsHandler _twitterStatisticsHandler;
private readonly ITwitterUserDal _twitterUserDal;
private readonly ICachedStatisticsService _cachedStatisticsService;
#region Ctor
public NodeInfoViewComponent(IModerationRepository moderationRepository, ITwitterStatisticsHandler twitterStatisticsHandler, ITwitterUserDal twitterUserDal)
public NodeInfoViewComponent(IModerationRepository moderationRepository, ICachedStatisticsService cachedStatisticsService)
{
_moderationRepository = moderationRepository;
_twitterStatisticsHandler = twitterStatisticsHandler;
_twitterUserDal = twitterUserDal;
_cachedStatisticsService = cachedStatisticsService;
}
#endregion
@ -30,7 +29,7 @@ namespace BirdsiteLive.Component
var followerPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower);
var twitterAccountPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount);
var statistics = await GetStatisticsAsync();
var statistics = await _cachedStatisticsService.GetStatisticsAsync();
var viewModel = new NodeInfoViewModel
{
@ -49,32 +48,6 @@ namespace BirdsiteLive.Component
//};
return View(viewModel);
}
private static CachedStatistics _cachedStatistics;
private async Task<CachedStatistics> GetStatisticsAsync() {
if (_cachedStatistics == null ||
(DateTime.UtcNow - _cachedStatistics.RefreshedTime).TotalMinutes > 15)
{
var twitterUserMax = _twitterStatisticsHandler.GetStatistics().UserCallsMax;
var twitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync();
var saturation = (int)((double)twitterUserCount / twitterUserMax * 100);
_cachedStatistics = new CachedStatistics
{
RefreshedTime = DateTime.UtcNow,
Saturation = saturation
};
}
return _cachedStatistics;
}
class CachedStatistics
{
public DateTime RefreshedTime { get; set; }
public int Saturation { get; set; }
}
}
public class NodeInfoViewModel

View File

@ -3,24 +3,56 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BirdsiteLive.Domain.Repository;
using BirdsiteLive.Services;
namespace BirdsiteLive.Controllers
{
public class AboutController : Controller
{
public IActionResult Index()
private readonly IModerationRepository _moderationRepository;
private readonly ICachedStatisticsService _cachedStatisticsService;
#region Ctor
public AboutController(IModerationRepository moderationRepository, ICachedStatisticsService cachedStatisticsService)
{
return View();
_moderationRepository = moderationRepository;
_cachedStatisticsService = cachedStatisticsService;
}
#endregion
public async Task<IActionResult> Index()
{
var stats = await _cachedStatisticsService.GetStatisticsAsync();
return View(stats);
}
public IActionResult Blacklisting()
{
return View("Blacklisting");
var status = GetModerationStatus();
return View("Blacklisting", status);
}
public IActionResult Whitelisting()
{
return View("Whitelisting");
var status = GetModerationStatus();
return View("Whitelisting", status);
}
private ModerationStatus GetModerationStatus()
{
var status = new ModerationStatus
{
Followers = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower),
TwitterAccounts = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount)
};
return status;
}
}
public class ModerationStatus
{
public ModerationTypeEnum Followers { get; set; }
public ModerationTypeEnum TwitterAccounts { get; set; }
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Threading.Tasks;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.Statistics.Domain;
namespace BirdsiteLive.Services
{
public interface ICachedStatisticsService
{
Task<CachedStatistics> GetStatisticsAsync();
}
public class CachedStatisticsService : ICachedStatisticsService
{
private readonly ITwitterStatisticsHandler _twitterStatisticsHandler;
private readonly ITwitterUserDal _twitterUserDal;
private static CachedStatistics _cachedStatistics;
#region Ctor
public CachedStatisticsService(ITwitterStatisticsHandler twitterStatisticsHandler, ITwitterUserDal twitterUserDal)
{
_twitterStatisticsHandler = twitterStatisticsHandler;
_twitterUserDal = twitterUserDal;
}
#endregion
public async Task<CachedStatistics> GetStatisticsAsync()
{
if (_cachedStatistics == null ||
(DateTime.UtcNow - _cachedStatistics.RefreshedTime).TotalMinutes > 15)
{
var twitterUserMax = _twitterStatisticsHandler.GetStatistics().UserCallsMax;
var twitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync();
var saturation = (int)((double)twitterUserCount / twitterUserMax * 100);
_cachedStatistics = new CachedStatistics
{
RefreshedTime = DateTime.UtcNow,
Saturation = saturation
};
}
return _cachedStatistics;
}
}
public class CachedStatistics
{
public DateTime RefreshedTime { get; set; }
public int Saturation { get; set; }
}
}

View File

@ -1,11 +1,26 @@
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
@using BirdsiteLive.Domain.Repository
@model BirdsiteLive.Controllers.ModerationStatus
@{
ViewData["Title"] = "Blacklisting";
}
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
<h2>Blacklisting</h2>
<p>
This node is using blacklisting.<br />
<br />
<br />
</p>
@if (Model.Followers == ModerationTypeEnum.BlackListing)
{
<p><br />This node is blacklisting some instances and/or Fediverse users.<br /><br /></p>
}
@if (Model.TwitterAccounts == ModerationTypeEnum.BlackListing)
{
<p><br />This node is blacklisting some twitter users.<br /><br /></p>
}
@if (Model.Followers != ModerationTypeEnum.BlackListing && Model.TwitterAccounts != ModerationTypeEnum.BlackListing)
{
<p><br />This node is not using blacklisting.<br /><br /></p>
}
<h2>FAQ</h2>
<p>TODO</p>

View File

@ -1,11 +1,15 @@

<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
@model BirdsiteLive.Services.CachedStatistics
@{
ViewData["Title"] = "About";
}
<div class="col-12 col-sm-12 col-md-10 col-lg-8 mx-auto">
<h2>Node Saturation</h2>
<p>
This node usage is at XX%<br />
<br />
<br />
<br/>
This node usage is at @Model.Saturation%<br/>
<br/>
</p>
<h2>FAQ</h2>
@ -15,10 +19,12 @@
<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>
<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>
<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

@ -1,11 +1,26 @@
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
<h2>Blacklisting</h2>
@using BirdsiteLive.Domain.Repository
@model BirdsiteLive.Controllers.ModerationStatus
@{
ViewData["Title"] = "Whitelisting";
}
<p>
This node is using whitelisting.<br />
<br />
<br />
</p>
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
<h2>Whitelisting</h2>
@if (Model.Followers == ModerationTypeEnum.WhiteListing)
{
<p><br />This node is whitelisting some instances and/or Fediverse users.<br /><br /></p>
}
@if (Model.TwitterAccounts == ModerationTypeEnum.WhiteListing)
{
<p><br />This node is whitelisting some twitter users.<br /><br /></p>
}
@if (Model.Followers != ModerationTypeEnum.WhiteListing && Model.TwitterAccounts != ModerationTypeEnum.WhiteListing)
{
<p><br />This node is not using whitelisting.<br /><br /></p>
}
<h2>FAQ</h2>
<p>TODO</p>