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
@@ -21,25 +21,16 @@ namespace PrivaPub.Domain.Social
|
||||
// server's reader (LocalActorService.ReaderUserName) follows every community in the feeds anyone reads, as Lemmy's own
|
||||
// follower of multi-communities does, and stops following one no feed holds any more. What it follows arrives as any
|
||||
// community's posts do; nobody's home shows them, the feed's timeline does.
|
||||
public class FeedFollows : IFeedFollows
|
||||
public class FeedFollows(
|
||||
DbEntities dbEntities,
|
||||
ILocalActorService localActors,
|
||||
IRemoteActorService remoteActors,
|
||||
IFollowService followService,
|
||||
IJobQueue jobQueue) : IFeedFollows
|
||||
{
|
||||
public const int MaxCommunities = 500;
|
||||
static readonly TimeSpan Stale = TimeSpan.FromDays(1);
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly IFollowService _follows;
|
||||
readonly IJobQueue _jobs;
|
||||
|
||||
public FeedFollows(DbEntities dbEntities, ILocalActorService localActors, IRemoteActorService remoteActors, IFollowService follows, IJobQueue jobs)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localActors = localActors;
|
||||
_remoteActors = remoteActors;
|
||||
_follows = follows;
|
||||
_jobs = jobs;
|
||||
}
|
||||
|
||||
public static Task<bool> Sync(IJobQueue jobs, CancellationToken token) =>
|
||||
jobs.Enqueue(JobKind.SyncFeeds, string.Empty, default, $"feeds|{Guid.NewGuid():N}", token);
|
||||
@@ -59,7 +50,7 @@ namespace PrivaPub.Domain.Social
|
||||
}
|
||||
else if ((await DB.Default.DeleteAsync<FeedSubscription>(s => s.AvatarId == me.Id && s.FeedActorURI == feed.ActorURI)).DeletedCount == 0)
|
||||
return true;
|
||||
await Sync(_jobs, token);
|
||||
await Sync(jobQueue, token);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,26 +60,26 @@ namespace PrivaPub.Domain.Social
|
||||
public async Task Reconcile(CancellationToken token)
|
||||
{
|
||||
var read = (await DB.Default.Find<FeedSubscription, string>().Project(s => s.FeedActorURI).ExecuteAsync(token)).Distinct().ToList();
|
||||
var feeds = await _dbEntities.ForeignAvatars.Match(a => read.Contains(a.ActorURI) && a.AvatarType == AvatarType.Feed && !a.DeletionAt.HasValue)
|
||||
var feeds = await dbEntities.ForeignAvatars.Match(a => read.Contains(a.ActorURI) && a.AvatarType == AvatarType.Feed && !a.DeletionAt.HasValue)
|
||||
.ExecuteAsync(token);
|
||||
// a feed's communities are as its server listed them a day ago at most (AccountCountsJob reads them, then asks
|
||||
// for this again)
|
||||
foreach (var stale in feeds.Where(f => !(DateTime.UtcNow - f.CountedAt < Stale)))
|
||||
if (Uri.TryCreate(stale.ActorURI, UriKind.Absolute, out var uri))
|
||||
await _jobs.Enqueue(JobKind.CountAccount, stale.ActorURI, uri.Host.ToLowerInvariant(), AccountCountsJob.DedupeKey(stale.ActorURI, DateTime.UtcNow), token);
|
||||
await jobQueue.Enqueue(JobKind.CountAccount, stale.ActorURI, uri.Host.ToLowerInvariant(), AccountCountsJob.DedupeKey(stale.ActorURI, DateTime.UtcNow), token);
|
||||
|
||||
var ours = _localActors.BaseAddress + "/";
|
||||
var ours = localActors.BaseAddress + "/";
|
||||
var wanted = feeds.SelectMany(f => f.FeedCommunities).Where(c => !c.StartsWith(ours, StringComparison.Ordinal))
|
||||
.Distinct(StringComparer.Ordinal).Take(MaxCommunities).ToHashSet(StringComparer.Ordinal);
|
||||
var reader = await _localActors.GetReaderActor(token);
|
||||
var following = await _dbEntities.Followings.Match(f => f.AvatarId == reader.Id).ExecuteAsync(token);
|
||||
var reader = await localActors.GetReaderActor(token);
|
||||
var following = await dbEntities.Followings.Match(f => f.AvatarId == reader.Id).ExecuteAsync(token);
|
||||
foreach (var gone in following.Where(f => !wanted.Contains(f.TargetActorURI)))
|
||||
await _follows.UnfollowAs(reader, gone.TargetActorURI, token);
|
||||
await followService.UnfollowAs(reader, gone.TargetActorURI, token);
|
||||
var followed = following.Select(f => f.TargetActorURI).ToHashSet(StringComparer.Ordinal);
|
||||
foreach (var community in wanted.Where(c => !followed.Contains(c)))
|
||||
// only a community: a feed lists nothing else, and the reader follows nothing else
|
||||
if (await _remoteActors.GetActor(community, refresh: false, token) is { AvatarType: AvatarType.Group })
|
||||
await _follows.FollowAs(reader, community, showReblogs: false, token);
|
||||
if (await remoteActors.GetActor(community, refresh: false, token) is { AvatarType: AvatarType.Group })
|
||||
await followService.FollowAs(reader, community, showReblogs: false, token: token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user