added node stats caching
This commit is contained in:
parent
45255fa39d
commit
ed8242834e
1 changed files with 29 additions and 4 deletions
|
@ -6,6 +6,7 @@ using BirdsiteLive.DAL.Contracts;
|
||||||
using BirdsiteLive.Domain.Repository;
|
using BirdsiteLive.Domain.Repository;
|
||||||
using BirdsiteLive.Statistics.Domain;
|
using BirdsiteLive.Statistics.Domain;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Razor.Language.Intermediate;
|
||||||
|
|
||||||
namespace BirdsiteLive.Component
|
namespace BirdsiteLive.Component
|
||||||
{
|
{
|
||||||
|
@ -29,9 +30,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 twitterUserMax = _twitterStatisticsHandler.GetStatistics().UserCallsMax;
|
var statistics = await GetStatisticsAsync();
|
||||||
var twitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync();
|
|
||||||
var saturation = (int)((double)twitterUserCount / twitterUserMax * 100);
|
|
||||||
|
|
||||||
var viewModel = new NodeInfoViewModel
|
var viewModel = new NodeInfoViewModel
|
||||||
{
|
{
|
||||||
|
@ -39,7 +38,7 @@ namespace BirdsiteLive.Component
|
||||||
twitterAccountPolicy == ModerationTypeEnum.BlackListing,
|
twitterAccountPolicy == ModerationTypeEnum.BlackListing,
|
||||||
WhitelistingEnabled = followerPolicy == ModerationTypeEnum.WhiteListing ||
|
WhitelistingEnabled = followerPolicy == ModerationTypeEnum.WhiteListing ||
|
||||||
twitterAccountPolicy == ModerationTypeEnum.WhiteListing,
|
twitterAccountPolicy == ModerationTypeEnum.WhiteListing,
|
||||||
InstanceSaturation = saturation,
|
InstanceSaturation = statistics.Saturation
|
||||||
};
|
};
|
||||||
|
|
||||||
//viewModel = new NodeInfoViewModel
|
//viewModel = new NodeInfoViewModel
|
||||||
|
@ -50,6 +49,32 @@ 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
|
||||||
|
|
Loading…
Add table
Reference in a new issue