The API's JSON is generated at build time, and no answer is an anonymous object
Build / Build (push) Successful in 36s

Every answer of the Mastodon API and the client API now has its JSON shape generated when the server is built, instead
of worked out by reflection while it runs; the bytes sent are unchanged. The small answers that were anonymous objects
(the instance documents, notification policies, reports, lists, tags, trends, errors and the empty answers) are named
types. A type without generated metadata fails at once in development and on the pasture, and in production is logged
and still answered. Three lists that were sent as lazy sequences (moderation reports, the published domain blocks and
the languages) are now built first.

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 07:28:02 +01:00
1 parent 8a1e4e419b
commit f3fdeaf038
41 files changed
+1333 -266

No files matched your search

@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
using MongoDB.Driver;
using MongoDB.Entities;
using PrivaPub.Api.Mastodon.Entities;
using PrivaPub.Api.Mastodon.Infrastructure;
using PrivaPub.Api.Mastodon.Mappers;
using PrivaPub.Domain.Privacy;
@@ -21,11 +22,11 @@ namespace PrivaPub.Api.Mastodon.Controllers
DbEntities dbEntities,
ILocalActorService localActors) : MastodonController
{
static List<object> History(Trends.Trend trend) => trend.History.Select(h => (object)new
static List<object> History(Trends.Trend trend) => trend.History.Select(h => (object)new TagHistoryEntity
{
day = new DateTimeOffset(h.Day, TimeSpan.Zero).ToUnixTimeSeconds().ToString(),
uses = h.Uses.ToString(),
accounts = h.Accounts.ToString()
Day = new DateTimeOffset(h.Day, TimeSpan.Zero).ToUnixTimeSeconds().ToString(),
Uses = h.Uses.ToString(),
Accounts = h.Accounts.ToString()
}).ToList();
IEnumerable<T> Window<T>(IEnumerable<T> items, int fallback, int max) =>
@@ -37,12 +38,12 @@ namespace PrivaPub.Api.Mastodon.Controllers
var followed = MyId == default
? new HashSet<string>()
: (await DB.Default.Find<Models.Social.FollowedTag>().Match(t => t.AvatarId == MyId).ExecuteAsync(token)).Select(t => t.Name).ToHashSet();
return Json(Window(await trendService.Tags(token), 10, 20).Select(t => new
return Json(Window(await trendService.Tags(token), 10, 20).Select(t => new TrendTagEntity
{
name = t.Key,
url = $"{localActors.BaseAddress}/tags/{Uri.EscapeDataString(t.Key)}",
history = History(t),
following = MyId == default ? default(bool?) : followed.Contains(t.Key)
Name = t.Key,
Url = $"{localActors.BaseAddress}/tags/{Uri.EscapeDataString(t.Key)}",
History = History(t),
Following = MyId == default ? default(bool?) : followed.Contains(t.Key)
}).ToList());
}
@@ -64,11 +65,11 @@ namespace PrivaPub.Api.Mastodon.Controllers
{
var link = samples[t.SamplePostId].Link;
var card = mapper.LinkCard(t.Key, link.Title, link.Description, link.ImageURL);
return card == default ? default : (object)new
return card == default ? default : (object)new TrendLinkEntity
{
card.Url, card.Title, card.Description, card.Type, card.AuthorName, card.AuthorUrl, card.ProviderName, card.ProviderUrl,
card.Html, card.Width, card.Height, card.Image, card.ImageDescription, card.EmbedUrl, card.Blurhash, card.Language,
card.PublishedAt, card.Authors, History = History(t)
Url = card.Url, Title = card.Title, Description = card.Description, Type = card.Type, AuthorName = card.AuthorName, AuthorUrl = card.AuthorUrl, ProviderName = card.ProviderName, ProviderUrl = card.ProviderUrl,
Html = card.Html, Width = card.Width, Height = card.Height, Image = card.Image, ImageDescription = card.ImageDescription, EmbedUrl = card.EmbedUrl, Blurhash = card.Blurhash, Language = card.Language,
PublishedAt = card.PublishedAt, Authors = card.Authors, History = History(t)
};
}).Where(c => c != default).ToList());
}