mirror of
https://github.com/NicolasConstant/BirdsiteLive
synced 2025-06-05 21:49:16 +02:00
Merge branch 'develop' into topic_admin-tooling
This commit is contained in:
@@ -46,7 +46,10 @@ namespace BirdsiteLive.Domain
|
|||||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
|
||||||
var result = await httpClient.GetAsync(objectId);
|
var result = await httpClient.GetAsync(objectId);
|
||||||
var content = await result.Content.ReadAsStringAsync();
|
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)
|
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
|
||||||
|
@@ -16,6 +16,7 @@ namespace BirdsiteLive.Pipeline.Tools
|
|||||||
|
|
||||||
private int _totalUsersCount = -1;
|
private int _totalUsersCount = -1;
|
||||||
private int _warmUpIterations;
|
private int _warmUpIterations;
|
||||||
|
private const int WarmUpMaxCapacity = 200;
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
public MaxUsersNumberProvider(InstanceSettings instanceSettings, ITwitterUserDal twitterUserDal)
|
public MaxUsersNumberProvider(InstanceSettings instanceSettings, ITwitterUserDal twitterUserDal)
|
||||||
@@ -31,8 +32,7 @@ namespace BirdsiteLive.Pipeline.Tools
|
|||||||
if (_totalUsersCount == -1)
|
if (_totalUsersCount == -1)
|
||||||
{
|
{
|
||||||
_totalUsersCount = await _twitterUserDal.GetTwitterUsersCountAsync();
|
_totalUsersCount = await _twitterUserDal.GetTwitterUsersCountAsync();
|
||||||
var warmUpMaxCapacity = _instanceSettings.MaxUsersCapacity / 4;
|
_warmUpIterations = (int)(_totalUsersCount / (float)WarmUpMaxCapacity);
|
||||||
_warmUpIterations = warmUpMaxCapacity == 0 ? 0 : (int)(_totalUsersCount / (float)warmUpMaxCapacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if warm up ended
|
// Return if warm up ended
|
||||||
@@ -40,7 +40,7 @@ namespace BirdsiteLive.Pipeline.Tools
|
|||||||
|
|
||||||
// Calculate warm up value
|
// Calculate warm up value
|
||||||
var maxUsers = _warmUpIterations > 0
|
var maxUsers = _warmUpIterations > 0
|
||||||
? _instanceSettings.MaxUsersCapacity / 4
|
? WarmUpMaxCapacity
|
||||||
: _instanceSettings.MaxUsersCapacity;
|
: _instanceSettings.MaxUsersCapacity;
|
||||||
_warmUpIterations--;
|
_warmUpIterations--;
|
||||||
return maxUsers;
|
return maxUsers;
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
<Version>0.16.1</Version>
|
<Version>0.16.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -5,12 +5,22 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace BirdsiteLive.Controllers
|
namespace BirdsiteLive.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class InboxController : ControllerBase
|
public class InboxController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private readonly ILogger<InboxController> _logger;
|
||||||
|
|
||||||
|
#region Ctor
|
||||||
|
public InboxController(ILogger<InboxController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
[Route("/inbox")]
|
[Route("/inbox")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Inbox()
|
public async Task<IActionResult> Inbox()
|
||||||
@@ -19,6 +29,8 @@ namespace BirdsiteLive.Controllers
|
|||||||
using (var reader = new StreamReader(Request.Body))
|
using (var reader = new StreamReader(Request.Body))
|
||||||
{
|
{
|
||||||
var body = await reader.ReadToEndAsync();
|
var body = await reader.ReadToEndAsync();
|
||||||
|
|
||||||
|
_logger.LogTrace("Inbox: {Body}", body);
|
||||||
//System.IO.File.WriteAllText($@"C:\apdebug\inbox\{Guid.NewGuid()}.json", body);
|
//System.IO.File.WriteAllText($@"C:\apdebug\inbox\{Guid.NewGuid()}.json", body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ using BirdsiteLive.Twitter;
|
|||||||
using BirdsiteLive.Twitter.Models;
|
using BirdsiteLive.Twitter.Models;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@@ -29,15 +30,17 @@ namespace BirdsiteLive.Controllers
|
|||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
private readonly IStatusService _statusService;
|
private readonly IStatusService _statusService;
|
||||||
private readonly InstanceSettings _instanceSettings;
|
private readonly InstanceSettings _instanceSettings;
|
||||||
|
private readonly ILogger<UsersController> _logger;
|
||||||
|
|
||||||
#region Ctor
|
#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;
|
_twitterUserService = twitterUserService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_statusService = statusService;
|
_statusService = statusService;
|
||||||
_instanceSettings = instanceSettings;
|
_instanceSettings = instanceSettings;
|
||||||
_twitterTweetService = twitterTweetService;
|
_twitterTweetService = twitterTweetService;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -57,6 +60,8 @@ namespace BirdsiteLive.Controllers
|
|||||||
[Route("/users/{id}")]
|
[Route("/users/{id}")]
|
||||||
public IActionResult Index(string id)
|
public IActionResult Index(string id)
|
||||||
{
|
{
|
||||||
|
_logger.LogTrace("User Index: {Id}", id);
|
||||||
|
|
||||||
id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant();
|
id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant();
|
||||||
|
|
||||||
// Ensure valid username
|
// Ensure valid username
|
||||||
@@ -131,6 +136,8 @@ namespace BirdsiteLive.Controllers
|
|||||||
using (var reader = new StreamReader(Request.Body))
|
using (var reader = new StreamReader(Request.Body))
|
||||||
{
|
{
|
||||||
var body = await reader.ReadToEndAsync();
|
var body = await reader.ReadToEndAsync();
|
||||||
|
|
||||||
|
_logger.LogTrace("User Inbox: {Body}", body);
|
||||||
//System.IO.File.WriteAllText($@"C:\apdebug\{Guid.NewGuid()}.json", body);
|
//System.IO.File.WriteAllText($@"C:\apdebug\{Guid.NewGuid()}.json", body);
|
||||||
|
|
||||||
var activity = ApDeserializer.ProcessActivity(body);
|
var activity = ApDeserializer.ProcessActivity(body);
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
"AdminEmail": "me@domain.name",
|
"AdminEmail": "me@domain.name",
|
||||||
"ResolveMentionsInProfiles": true,
|
"ResolveMentionsInProfiles": true,
|
||||||
"PublishReplies": false,
|
"PublishReplies": false,
|
||||||
"MaxUsersCapacity": 800,
|
"MaxUsersCapacity": 1500,
|
||||||
"UnlistedTwitterAccounts": null
|
"UnlistedTwitterAccounts": null
|
||||||
},
|
},
|
||||||
"Db": {
|
"Db": {
|
||||||
|
@@ -30,16 +30,19 @@ namespace BirdsiteLive.Pipeline.Tests.Tools
|
|||||||
var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object);
|
var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object);
|
||||||
|
|
||||||
var result = await provider.GetMaxUsersNumberAsync();
|
var result = await provider.GetMaxUsersNumberAsync();
|
||||||
Assert.AreEqual(250, result);
|
Assert.AreEqual(200, result);
|
||||||
|
|
||||||
result = await provider.GetMaxUsersNumberAsync();
|
result = await provider.GetMaxUsersNumberAsync();
|
||||||
Assert.AreEqual(250, result);
|
Assert.AreEqual(200, result);
|
||||||
|
|
||||||
result = await provider.GetMaxUsersNumberAsync();
|
result = await provider.GetMaxUsersNumberAsync();
|
||||||
Assert.AreEqual(250, result);
|
Assert.AreEqual(200, result);
|
||||||
|
|
||||||
result = await provider.GetMaxUsersNumberAsync();
|
result = await provider.GetMaxUsersNumberAsync();
|
||||||
Assert.AreEqual(250, result);
|
Assert.AreEqual(200, result);
|
||||||
|
|
||||||
|
result = await provider.GetMaxUsersNumberAsync();
|
||||||
|
Assert.AreEqual(200, result);
|
||||||
|
|
||||||
result = await provider.GetMaxUsersNumberAsync();
|
result = await provider.GetMaxUsersNumberAsync();
|
||||||
Assert.AreEqual(1000, result);
|
Assert.AreEqual(1000, result);
|
||||||
@@ -63,7 +66,7 @@ namespace BirdsiteLive.Pipeline.Tests.Tools
|
|||||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||||
twitterUserDalMock
|
twitterUserDalMock
|
||||||
.Setup(x => x.GetTwitterUsersCountAsync())
|
.Setup(x => x.GetTwitterUsersCountAsync())
|
||||||
.ReturnsAsync(249);
|
.ReturnsAsync(199);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object);
|
var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object);
|
||||||
|
Reference in New Issue
Block a user