House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
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:
thepraandClaude Opus 5.5 committed 2026-11-10 01:24:43 +01:00
1 parent f0a14c737f
commit 0f73f69239
176 files changed
+2789 -3974

No files matched your search

+18 -30
View File
@@ -14,28 +14,16 @@ namespace PrivaPub.Federation.Actors
// once a day, never when someone looks at it; a hidden or missing collection leaves its count unknown. Mastodon and
// GoToSocial do the same. A feed's following is its communities: they are kept, and read in turn, so its list shows.
// Its featured hashtags (its featuredTags collection, R8) are read with them.
public class AccountCountsJob : IJobHandler
public class AccountCountsJob(
IRemoteActorService remoteActors,
DbEntities dbEntities,
IFeaturedPosts featured = default,
ILocalActorService localActors = default,
IJobQueue jobs = default,
Domain.Social.IFeaturedTags featuredTags = default) : IJobHandler
{
readonly IRemoteActorService _remoteActors;
readonly DbEntities _dbEntities;
readonly IFeaturedPosts _featured;
readonly ILocalActorService _localActors;
readonly IJobQueue _jobs;
readonly Domain.Social.IFeaturedTags _featuredTags;
public const int MaxFeedCommunities = 50;
public AccountCountsJob(IRemoteActorService remoteActors, DbEntities dbEntities, IFeaturedPosts featured = default,
ILocalActorService localActors = default, IJobQueue jobs = default, Domain.Social.IFeaturedTags featuredTags = default)
{
_featuredTags = featuredTags;
_remoteActors = remoteActors;
_dbEntities = dbEntities;
_featured = featured;
_localActors = localActors;
_jobs = jobs;
}
public JobKind Kind => JobKind.CountAccount;
public int Concurrency => 2;
public int MaxAttempts => 2;
@@ -45,7 +33,7 @@ namespace PrivaPub.Federation.Actors
public async Task<JobOutcome> Handle(Job job, CancellationToken token)
{
var actor = await _dbEntities.ForeignAvatars.Match(a => a.ActorURI == job.Payload && !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
var actor = await dbEntities.ForeignAvatars.Match(a => a.ActorURI == job.Payload && !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
if (actor == default)
return JobOutcome.Done;
var feed = actor.AvatarType == AvatarType.Feed;
@@ -62,15 +50,15 @@ namespace PrivaPub.Federation.Actors
if (feed && listed)
{
foreach (var community in communities)
if (_localActors == default || !community.StartsWith(_localActors.BaseAddress + "/", StringComparison.Ordinal))
await _remoteActors.GetActor(community, refresh: false, token);
if (_jobs != default && await DB.Default.Find<Models.Social.FeedSubscription>().Match(s => s.FeedActorURI == actor.ActorURI).ExecuteAnyAsync(token))
await Domain.Social.FeedFollows.Sync(_jobs, token);
if (localActors == default || !community.StartsWith(localActors.BaseAddress + "/", StringComparison.Ordinal))
await remoteActors.GetActor(community, refresh: false, token);
if (jobs != default && await DB.Default.Find<Models.Social.FeedSubscription>().Match(s => s.FeedActorURI == actor.ActorURI).ExecuteAnyAsync(token))
await Domain.Social.FeedFollows.Sync(jobs, token);
}
if (_featured != default)
await _featured.Sync(actor, token);
if (_featuredTags != default)
await _featuredTags.Sync(actor, token);
if (featured != default)
await featured.Sync(actor, token);
if (featuredTags != default)
await featuredTags.Sync(actor, token);
return JobOutcome.Done;
}
@@ -82,7 +70,7 @@ namespace PrivaPub.Federation.Actors
if (string.IsNullOrEmpty(collection) || !Origin.Same(collection, actor.ActorURI))
return (default, listed, false);
using var scope = HttpScope.For("collection");
using var fetched = await _remoteActors.FetchObject(collection, token);
using var fetched = await remoteActors.FetchObject(collection, token);
if (fetched == default || fetched.Root.ValueKind != System.Text.Json.JsonValueKind.Object)
return (default, listed, false);
int? total = fetched.Root.TryGetProperty("totalItems", out var counted) && counted.TryGetInt32(out var count) && count >= 0 ? count : default;
@@ -92,7 +80,7 @@ namespace PrivaPub.Federation.Actors
var page = document["orderedItems"] ?? document["items"] ?? document["first"]?["orderedItems"] ?? document["first"]?["items"];
if (page == default && ActivityJson.Id(document["first"]) is { } first && Origin.Same(first, actor.ActorURI))
{
using var next = await _remoteActors.FetchObject(first, token);
using var next = await remoteActors.FetchObject(first, token);
if (next == default)
return (total, listed, false);
var nextPage = System.Text.Json.Nodes.JsonNode.Parse(next.Root.GetRawText());