House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
Build / Build (push) Successful in 30s
- Services, controllers and jobs take their dependencies through primary constructors and use them directly; where a method already named a local after a dependency, the dependency takes its type's name. - Every async method takes a CancellationToken last and passes it down to MongoDB, HTTP and the job queue. The setup claim is still given back when a request is cancelled. - The federation and media options are read through IOptionsMonitor. - The Mastodon entities keep sending "" for empty strings, and every model field where null means something says so. - The inbox's 503 with Retry-After, which other servers retry, is the one server error left, and says why. - Arasaka.HouseRules.Analyzers checks all of this in every build, here and in PrivaPub.ClientModels as decePubClient builds it. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -27,7 +27,11 @@ namespace PrivaPub.Federation.Inbox
|
||||
// replies' own, two levels down. Read with the instance actor's signature, never a persona's, a few pages and at most
|
||||
// MaxItems posts a job; each one is fetched from its own server and stored like any post fetched for a thread
|
||||
// (RemotePosts.StoreContext: public and unlisted only, its author checked against its origin).
|
||||
public class RepliesJobHandler : IJobHandler
|
||||
public class RepliesJobHandler(
|
||||
DbEntities dbEntities,
|
||||
IRemoteActorService remoteActors,
|
||||
IRemotePosts remotePosts,
|
||||
IJobQueue queue) : IJobHandler
|
||||
{
|
||||
public const int MaxPages = 5;
|
||||
public const int MaxItems = 100;
|
||||
@@ -39,18 +43,6 @@ namespace PrivaPub.Federation.Inbox
|
||||
"Collection", "OrderedCollection", "CollectionPage", "OrderedCollectionPage"
|
||||
};
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly IRemotePosts _remotePosts;
|
||||
readonly IJobQueue _queue;
|
||||
|
||||
public RepliesJobHandler(DbEntities dbEntities, IRemoteActorService remoteActors, IRemotePosts remotePosts, IJobQueue queue)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_remoteActors = remoteActors;
|
||||
_remotePosts = remotePosts;
|
||||
_queue = queue;
|
||||
}
|
||||
|
||||
public JobKind Kind => JobKind.FetchReplies;
|
||||
public int Concurrency => 2;
|
||||
@@ -69,7 +61,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
public async Task<JobOutcome> Handle(Job job, CancellationToken token)
|
||||
{
|
||||
var payload = JsonSerializer.Deserialize<RepliesPayload>(job.Payload);
|
||||
var post = await _dbEntities.Posts.MatchID(payload.PostId).ExecuteFirstAsync(token);
|
||||
var post = await dbEntities.Posts.MatchID(payload.PostId).ExecuteFirstAsync(token);
|
||||
if (post is not { IsFederatedCopy: true, Visibility: PostVisibility.Public or PostVisibility.Unlisted } || post.DeletedAt.HasValue
|
||||
|| string.IsNullOrEmpty(post.ObjectURI))
|
||||
return JobOutcome.Done;
|
||||
@@ -80,7 +72,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
{
|
||||
var uri = Id(document[name]);
|
||||
// Forte's `context` is the thread's first post
|
||||
if (uri != default && await _dbEntities.Posts.Match(p => p.ObjectURI == uri).ExecuteAnyAsync(token))
|
||||
if (uri != default && await dbEntities.Posts.Match(p => p.ObjectURI == uri).ExecuteAnyAsync(token))
|
||||
continue;
|
||||
var known = uri == default ? default : await DB.Default.Find<ThreadCollection>().Match(c => c.URI == uri).ExecuteFirstAsync(token);
|
||||
var (thread, etag, unchanged) = await Collection(document[name], known?.ETag, token);
|
||||
@@ -106,7 +98,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
return JobOutcome.Done;
|
||||
var (answers, _) = await StoreAll(replies, false, token);
|
||||
if (payload.Depth < MaxDepth)
|
||||
await _queue.EnqueueMany(answers.Where(a => a.IsFederatedCopy && a.AnsweringToPostId == post.ID).Take(MaxBranches)
|
||||
await queue.EnqueueMany(answers.Where(a => a.IsFederatedCopy && a.AnsweringToPostId == post.ID).Take(MaxBranches)
|
||||
.Select(a => For(a, payload.Depth + 1)), token);
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
@@ -119,7 +111,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
if (record != default)
|
||||
return JsonNode.Parse(record.Raw) as JsonObject;
|
||||
using var scope = HttpScope.For("replies");
|
||||
using var fetched = await _remoteActors.FetchObject(post.ObjectURI, token);
|
||||
using var fetched = await remoteActors.FetchObject(post.ObjectURI, token);
|
||||
return fetched == default ? default : JsonNode.Parse(fetched.Root.GetRawText()) as JsonObject;
|
||||
}
|
||||
|
||||
@@ -133,7 +125,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
if (uri != default && Uri.TryCreate(uri, UriKind.Absolute, out var parsed) && (parsed.Scheme == Uri.UriSchemeHttps || parsed.Scheme == Uri.UriSchemeHttp))
|
||||
{
|
||||
using var scope = HttpScope.For("replies");
|
||||
using var fetched = await _remoteActors.FetchObject(uri, etag, token);
|
||||
using var fetched = await remoteActors.FetchObject(uri, etag, token);
|
||||
if (fetched?.NotModified == true)
|
||||
return (default, etag, true);
|
||||
node = fetched == default ? default : JsonNode.Parse(fetched.Root.GetRawText());
|
||||
@@ -160,8 +152,8 @@ namespace PrivaPub.Federation.Inbox
|
||||
var id = activities ? await Added(item, token) : PostId(item);
|
||||
if (id == default)
|
||||
continue;
|
||||
var post = await _dbEntities.Posts.Match(p => p.ObjectURI == id && !p.DeletedAt.HasValue).ExecuteFirstAsync(token)
|
||||
?? await _remotePosts.StoreContext(id, 0, token);
|
||||
var post = await dbEntities.Posts.Match(p => p.ObjectURI == id && !p.DeletedAt.HasValue).ExecuteFirstAsync(token)
|
||||
?? await remotePosts.StoreContext(id, 0, token);
|
||||
if (post != default)
|
||||
posts.Add(post);
|
||||
}
|
||||
@@ -200,7 +192,7 @@ namespace PrivaPub.Federation.Inbox
|
||||
if (node is JsonValue && Id(node) is { } uri)
|
||||
{
|
||||
using var scope = HttpScope.For("replies");
|
||||
using var fetched = await _remoteActors.FetchObject(uri, token);
|
||||
using var fetched = await remoteActors.FetchObject(uri, token);
|
||||
node = fetched == default ? default : JsonNode.Parse(fetched.Root.GetRawText());
|
||||
}
|
||||
return node as JsonObject;
|
||||
|
||||
Reference in new issue
Block a user