displaying node infos
This commit is contained in:
parent
7abc4a3b3e
commit
7503f34882
6 changed files with 152 additions and 58 deletions
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BirdsiteLive.DAL.Contracts;
|
using BirdsiteLive.DAL.Contracts;
|
||||||
using BirdsiteLive.Domain.Repository;
|
using BirdsiteLive.Domain.Repository;
|
||||||
|
using BirdsiteLive.Services;
|
||||||
using BirdsiteLive.Statistics.Domain;
|
using BirdsiteLive.Statistics.Domain;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Razor.Language.Intermediate;
|
using Microsoft.AspNetCore.Razor.Language.Intermediate;
|
||||||
|
@ -13,15 +14,13 @@ namespace BirdsiteLive.Component
|
||||||
public class NodeInfoViewComponent : ViewComponent
|
public class NodeInfoViewComponent : ViewComponent
|
||||||
{
|
{
|
||||||
private readonly IModerationRepository _moderationRepository;
|
private readonly IModerationRepository _moderationRepository;
|
||||||
private readonly ITwitterStatisticsHandler _twitterStatisticsHandler;
|
private readonly ICachedStatisticsService _cachedStatisticsService;
|
||||||
private readonly ITwitterUserDal _twitterUserDal;
|
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
public NodeInfoViewComponent(IModerationRepository moderationRepository, ITwitterStatisticsHandler twitterStatisticsHandler, ITwitterUserDal twitterUserDal)
|
public NodeInfoViewComponent(IModerationRepository moderationRepository, ICachedStatisticsService cachedStatisticsService)
|
||||||
{
|
{
|
||||||
_moderationRepository = moderationRepository;
|
_moderationRepository = moderationRepository;
|
||||||
_twitterStatisticsHandler = twitterStatisticsHandler;
|
_cachedStatisticsService = cachedStatisticsService;
|
||||||
_twitterUserDal = twitterUserDal;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ namespace BirdsiteLive.Component
|
||||||
var followerPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower);
|
var followerPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower);
|
||||||
var twitterAccountPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount);
|
var twitterAccountPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount);
|
||||||
|
|
||||||
var statistics = await GetStatisticsAsync();
|
var statistics = await _cachedStatisticsService.GetStatisticsAsync();
|
||||||
|
|
||||||
var viewModel = new NodeInfoViewModel
|
var viewModel = new NodeInfoViewModel
|
||||||
{
|
{
|
||||||
|
@ -49,32 +48,6 @@ namespace BirdsiteLive.Component
|
||||||
//};
|
//};
|
||||||
return View(viewModel);
|
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
|
public class NodeInfoViewModel
|
||||||
|
|
|
@ -3,24 +3,56 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BirdsiteLive.Domain.Repository;
|
||||||
|
using BirdsiteLive.Services;
|
||||||
|
|
||||||
namespace BirdsiteLive.Controllers
|
namespace BirdsiteLive.Controllers
|
||||||
{
|
{
|
||||||
public class AboutController : Controller
|
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()
|
public IActionResult Blacklisting()
|
||||||
{
|
{
|
||||||
return View("Blacklisting");
|
var status = GetModerationStatus();
|
||||||
|
return View("Blacklisting", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Whitelisting()
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
53
src/BirdsiteLive/Services/CachedStatisticsService.cs
Normal file
53
src/BirdsiteLive/Services/CachedStatisticsService.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
<h2>Blacklisting</h2>
|
||||||
|
|
||||||
<p>
|
@if (Model.Followers == ModerationTypeEnum.BlackListing)
|
||||||
This node is using blacklisting.<br />
|
{
|
||||||
<br />
|
<p><br />This node is blacklisting some instances and/or Fediverse users.<br /><br /></p>
|
||||||
<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>
|
<h2>FAQ</h2>
|
||||||
<p>TODO</p>
|
<p>TODO</p>
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
|
@model BirdsiteLive.Services.CachedStatistics
|
||||||
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
|
@{
|
||||||
|
ViewData["Title"] = "About";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="col-12 col-sm-12 col-md-10 col-lg-8 mx-auto">
|
||||||
<h2>Node Saturation</h2>
|
<h2>Node Saturation</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This node usage is at XX%<br />
|
<br/>
|
||||||
<br />
|
This node usage is at @Model.Saturation%<br/>
|
||||||
<br />
|
<br/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>FAQ</h2>
|
<h2>FAQ</h2>
|
||||||
|
@ -15,8 +19,10 @@
|
||||||
|
|
||||||
<h4>What happen when the node is saturated?</h4>
|
<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 />
|
<p>
|
||||||
The software doesn't scale, and it's by design.</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>
|
<h4>How can I reduce the node's saturation?</h4>
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,26 @@
|
||||||
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
|
@using BirdsiteLive.Domain.Repository
|
||||||
<h2>Blacklisting</h2>
|
@model BirdsiteLive.Controllers.ModerationStatus
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Whitelisting";
|
||||||
|
}
|
||||||
|
|
||||||
<p>
|
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
|
||||||
This node is using whitelisting.<br />
|
<h2>Whitelisting</h2>
|
||||||
<br />
|
|
||||||
<br />
|
@if (Model.Followers == ModerationTypeEnum.WhiteListing)
|
||||||
</p>
|
{
|
||||||
|
<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>
|
<h2>FAQ</h2>
|
||||||
<p>TODO</p>
|
<p>TODO</p>
|
||||||
|
|
Loading…
Add table
Reference in a new issue