diff --git a/src/BirdsiteLive/Component/NodeInfoViewComponent.cs b/src/BirdsiteLive/Component/NodeInfoViewComponent.cs index d86c34e..deb10a9 100644 --- a/src/BirdsiteLive/Component/NodeInfoViewComponent.cs +++ b/src/BirdsiteLive/Component/NodeInfoViewComponent.cs @@ -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 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 diff --git a/src/BirdsiteLive/Controllers/AboutController.cs b/src/BirdsiteLive/Controllers/AboutController.cs index f9a015d..e64a147 100644 --- a/src/BirdsiteLive/Controllers/AboutController.cs +++ b/src/BirdsiteLive/Controllers/AboutController.cs @@ -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 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; } + } } diff --git a/src/BirdsiteLive/Services/CachedStatisticsService.cs b/src/BirdsiteLive/Services/CachedStatisticsService.cs new file mode 100644 index 0000000..e32e0f8 --- /dev/null +++ b/src/BirdsiteLive/Services/CachedStatisticsService.cs @@ -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 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 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; } + } +} \ No newline at end of file diff --git a/src/BirdsiteLive/Views/About/Blacklisting.cshtml b/src/BirdsiteLive/Views/About/Blacklisting.cshtml index bf92930..a278912 100644 --- a/src/BirdsiteLive/Views/About/Blacklisting.cshtml +++ b/src/BirdsiteLive/Views/About/Blacklisting.cshtml @@ -1,11 +1,26 @@ -
+@using BirdsiteLive.Domain.Repository +@model BirdsiteLive.Controllers.ModerationStatus +@{ + ViewData["Title"] = "Blacklisting"; +} + +

Blacklisting

-

- This node is using blacklisting.
-
-
-

+ @if (Model.Followers == ModerationTypeEnum.BlackListing) + { +


This node is blacklisting some instances and/or Fediverse users.

+ } + + @if (Model.TwitterAccounts == ModerationTypeEnum.BlackListing) + { +


This node is blacklisting some twitter users.

+ } + + @if (Model.Followers != ModerationTypeEnum.BlackListing && Model.TwitterAccounts != ModerationTypeEnum.BlackListing) + { +


This node is not using blacklisting.

+ }

FAQ

TODO

diff --git a/src/BirdsiteLive/Views/About/Index.cshtml b/src/BirdsiteLive/Views/About/Index.cshtml index dd203cd..1f16b09 100644 --- a/src/BirdsiteLive/Views/About/Index.cshtml +++ b/src/BirdsiteLive/Views/About/Index.cshtml @@ -1,11 +1,15 @@ - -
+@model BirdsiteLive.Services.CachedStatistics +@{ + ViewData["Title"] = "About"; +} + +

Node Saturation

- This node usage is at XX%
-
-
+
+ This node usage is at @Model.Saturation%
+

FAQ

@@ -15,10 +19,12 @@

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.

+

+ 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.

+

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/BirdsiteLive/Views/About/Whitelisting.cshtml b/src/BirdsiteLive/Views/About/Whitelisting.cshtml index 9d2c978..9cdebd6 100644 --- a/src/BirdsiteLive/Views/About/Whitelisting.cshtml +++ b/src/BirdsiteLive/Views/About/Whitelisting.cshtml @@ -1,11 +1,26 @@ -
-

Blacklisting

+@using BirdsiteLive.Domain.Repository +@model BirdsiteLive.Controllers.ModerationStatus +@{ + ViewData["Title"] = "Whitelisting"; +} -

- This node is using whitelisting.
-
-
-

+
+

Whitelisting

+ + @if (Model.Followers == ModerationTypeEnum.WhiteListing) + { +


This node is whitelisting some instances and/or Fediverse users.

+ } + + @if (Model.TwitterAccounts == ModerationTypeEnum.WhiteListing) + { +


This node is whitelisting some twitter users.

+ } + + @if (Model.Followers != ModerationTypeEnum.WhiteListing && Model.TwitterAccounts != ModerationTypeEnum.WhiteListing) + { +


This node is not using whitelisting.

+ }

FAQ

TODO