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
@@ -20,26 +20,20 @@ namespace PrivaPub.Domain.Timelines
|
||||
Task<WebResult> MarkNotificationsRead(string rootUserId, string avatarId, CancellationToken token);
|
||||
}
|
||||
|
||||
public class TimelineService : ITimelineService
|
||||
public class TimelineService(
|
||||
DbEntities dbEntities,
|
||||
IStringLocalizer<GenericRes> localizer) : ITimelineService
|
||||
{
|
||||
const int MaxLimit = 40;
|
||||
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly IStringLocalizer<GenericRes> _localizer;
|
||||
|
||||
public TimelineService(DbEntities dbEntities, IStringLocalizer<GenericRes> localizer)
|
||||
{
|
||||
_dbEntities = dbEntities;
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public async Task<WebResult> Home(string rootUserId, string avatarId, string maxId, int limit, CancellationToken token)
|
||||
{
|
||||
var result = new WebResult();
|
||||
if (!await Owns(rootUserId, avatarId, token))
|
||||
return result.Invalidate(_localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
|
||||
var query = _dbEntities.TimelineEntries.Match(e => e.AvatarId == avatarId);
|
||||
var query = dbEntities.TimelineEntries.Match(e => e.AvatarId == avatarId);
|
||||
if (!string.IsNullOrEmpty(maxId))
|
||||
query.Match(f => f.Lt(e => e.PostId, maxId));
|
||||
var entries = await query.Sort(e => e.PostId, Order.Descending).Limit(Math.Clamp(limit, 1, MaxLimit)).ExecuteAsync(token);
|
||||
@@ -47,7 +41,7 @@ namespace PrivaPub.Domain.Timelines
|
||||
var ids = entries.Select(e => e.PostId).Concat(entries.Where(e => e.ReblogOfPostId != default).Select(e => e.ReblogOfPostId)).Distinct().ToList();
|
||||
var posts = ids.Count == 0
|
||||
? new Dictionary<string, Post>()
|
||||
: (await _dbEntities.Posts.Match(p => ids.Contains(p.ID)).Match(VisibilityPolicy.IsShown).ExecuteAsync(token)).ToDictionary(p => p.ID);
|
||||
: (await dbEntities.Posts.Match(p => ids.Contains(p.ID)).Match(VisibilityPolicy.IsShown).ExecuteAsync(token)).ToDictionary(p => p.ID);
|
||||
|
||||
result.Data = entries
|
||||
.Where(e => posts.ContainsKey(e.PostId) && (e.ReblogOfPostId == default || posts.ContainsKey(e.ReblogOfPostId)))
|
||||
@@ -66,9 +60,9 @@ namespace PrivaPub.Domain.Timelines
|
||||
{
|
||||
var result = new WebResult();
|
||||
if (!await Owns(rootUserId, avatarId, token))
|
||||
return result.Invalidate(_localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
|
||||
var query = _dbEntities.Notifications.Match(n => n.AvatarId == avatarId);
|
||||
var query = dbEntities.Notifications.Match(n => n.AvatarId == avatarId);
|
||||
if (!string.IsNullOrEmpty(maxId))
|
||||
query.Match(f => f.Lt(n => n.ID, maxId));
|
||||
result.Data = (await query.Sort(n => n.ID, Order.Descending).Limit(Math.Clamp(limit, 1, MaxLimit)).ExecuteAsync(token))
|
||||
@@ -90,14 +84,14 @@ namespace PrivaPub.Domain.Timelines
|
||||
{
|
||||
var result = new WebResult();
|
||||
if (!await Owns(rootUserId, avatarId, token))
|
||||
return result.Invalidate(_localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
await DB.Default.Update<Notification>().Match(n => n.AvatarId == avatarId && !n.IsRead).Modify(n => n.IsRead, true).ExecuteAsync(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
async Task<bool> Owns(string rootUserId, string avatarId, CancellationToken token) =>
|
||||
!string.IsNullOrEmpty(rootUserId) && !string.IsNullOrEmpty(avatarId)
|
||||
&& await _dbEntities.RootToAvatars.Match(ra => ra.RootId == rootUserId && ra.AvatarId == avatarId).ExecuteAnyAsync(token);
|
||||
&& await dbEntities.RootToAvatars.Match(ra => ra.RootId == rootUserId && ra.AvatarId == avatarId).ExecuteAnyAsync(token);
|
||||
|
||||
static ViewPost ToView(Post post) => new()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user