Merge branch 'develop' into topic_admin-tooling

This commit is contained in:
Nicolas Constant 2021-04-15 21:23:34 -04:00
commit d95163f696
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
7 changed files with 38 additions and 13 deletions

View file

@ -46,7 +46,10 @@ namespace BirdsiteLive.Domain
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
var result = await httpClient.GetAsync(objectId);
var content = await result.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<Actor>(content);
var actor = JsonConvert.DeserializeObject<Actor>(content);
if (string.IsNullOrWhiteSpace(actor.url)) actor.url = objectId;
return actor;
}
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)

View file

@ -16,6 +16,7 @@ namespace BirdsiteLive.Pipeline.Tools
private int _totalUsersCount = -1;
private int _warmUpIterations;
private const int WarmUpMaxCapacity = 200;
#region Ctor
public MaxUsersNumberProvider(InstanceSettings instanceSettings, ITwitterUserDal twitterUserDal)
@ -31,8 +32,7 @@ namespace BirdsiteLive.Pipeline.Tools
if (_totalUsersCount == -1)
{
_totalUsersCount = await _twitterUserDal.GetTwitterUsersCountAsync();
var warmUpMaxCapacity = _instanceSettings.MaxUsersCapacity / 4;
_warmUpIterations = warmUpMaxCapacity == 0 ? 0 : (int)(_totalUsersCount / (float)warmUpMaxCapacity);
_warmUpIterations = (int)(_totalUsersCount / (float)WarmUpMaxCapacity);
}
// Return if warm up ended
@ -40,7 +40,7 @@ namespace BirdsiteLive.Pipeline.Tools
// Calculate warm up value
var maxUsers = _warmUpIterations > 0
? _instanceSettings.MaxUsersCapacity / 4
? WarmUpMaxCapacity
: _instanceSettings.MaxUsersCapacity;
_warmUpIterations--;
return maxUsers;

View file

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>0.16.1</Version>
<Version>0.16.2</Version>
</PropertyGroup>
<ItemGroup>

View file

@ -5,12 +5,22 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace BirdsiteLive.Controllers
{
[ApiController]
public class InboxController : ControllerBase
{
private readonly ILogger<InboxController> _logger;
#region Ctor
public InboxController(ILogger<InboxController> logger)
{
_logger = logger;
}
#endregion
[Route("/inbox")]
[HttpPost]
public async Task<IActionResult> Inbox()
@ -19,6 +29,8 @@ namespace BirdsiteLive.Controllers
using (var reader = new StreamReader(Request.Body))
{
var body = await reader.ReadToEndAsync();
_logger.LogTrace("Inbox: {Body}", body);
//System.IO.File.WriteAllText($@"C:\apdebug\inbox\{Guid.NewGuid()}.json", body);
}

View file

@ -17,6 +17,7 @@ using BirdsiteLive.Twitter;
using BirdsiteLive.Twitter.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
@ -29,15 +30,17 @@ namespace BirdsiteLive.Controllers
private readonly IUserService _userService;
private readonly IStatusService _statusService;
private readonly InstanceSettings _instanceSettings;
private readonly ILogger<UsersController> _logger;
#region Ctor
public UsersController(ITwitterUserService twitterUserService, IUserService userService, IStatusService statusService, InstanceSettings instanceSettings, ITwitterTweetsService twitterTweetService)
public UsersController(ITwitterUserService twitterUserService, IUserService userService, IStatusService statusService, InstanceSettings instanceSettings, ITwitterTweetsService twitterTweetService, ILogger<UsersController> logger)
{
_twitterUserService = twitterUserService;
_userService = userService;
_statusService = statusService;
_instanceSettings = instanceSettings;
_twitterTweetService = twitterTweetService;
_logger = logger;
}
#endregion
@ -57,6 +60,8 @@ namespace BirdsiteLive.Controllers
[Route("/users/{id}")]
public IActionResult Index(string id)
{
_logger.LogTrace("User Index: {Id}", id);
id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant();
// Ensure valid username
@ -131,6 +136,8 @@ namespace BirdsiteLive.Controllers
using (var reader = new StreamReader(Request.Body))
{
var body = await reader.ReadToEndAsync();
_logger.LogTrace("User Inbox: {Body}", body);
//System.IO.File.WriteAllText($@"C:\apdebug\{Guid.NewGuid()}.json", body);
var activity = ApDeserializer.ProcessActivity(body);

View file

@ -20,7 +20,7 @@
"AdminEmail": "me@domain.name",
"ResolveMentionsInProfiles": true,
"PublishReplies": false,
"MaxUsersCapacity": 800,
"MaxUsersCapacity": 1500,
"UnlistedTwitterAccounts": null
},
"Db": {

View file

@ -30,17 +30,20 @@ namespace BirdsiteLive.Pipeline.Tests.Tools
var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object);
var result = await provider.GetMaxUsersNumberAsync();
Assert.AreEqual(250, result);
Assert.AreEqual(200, result);
result = await provider.GetMaxUsersNumberAsync();
Assert.AreEqual(250, result);
Assert.AreEqual(200, result);
result = await provider.GetMaxUsersNumberAsync();
Assert.AreEqual(250, result);
Assert.AreEqual(200, result);
result = await provider.GetMaxUsersNumberAsync();
Assert.AreEqual(250, result);
Assert.AreEqual(200, result);
result = await provider.GetMaxUsersNumberAsync();
Assert.AreEqual(200, result);
result = await provider.GetMaxUsersNumberAsync();
Assert.AreEqual(1000, result);
@ -63,7 +66,7 @@ namespace BirdsiteLive.Pipeline.Tests.Tools
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
twitterUserDalMock
.Setup(x => x.GetTwitterUsersCountAsync())
.ReturnsAsync(249);
.ReturnsAsync(199);
#endregion
var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object);