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

+9 -14
View File
@@ -23,14 +23,14 @@ namespace PrivaPub.Infrastructure.Geo
public string Source => default;
}
public sealed class DbIpLocator : IGeoLocator, IDisposable
public sealed class DbIpLocator(
IOptionsMonitor<StatisticsOptions> options,
ILogger<DbIpLocator> logger) : IGeoLocator, IDisposable
{
public static readonly string CityFile = GeoUpdater.FileOf("city");
public static readonly string AsnFile = GeoUpdater.FileOf("asn");
static readonly TimeSpan CheckInterval = TimeSpan.FromMinutes(10);
readonly IOptionsMonitor<StatisticsOptions> _options;
readonly ILogger<DbIpLocator> _logger;
readonly object _lock = new();
Reader _city;
Reader _asn;
@@ -39,12 +39,6 @@ namespace PrivaPub.Infrastructure.Geo
DateTime _checkedAt = DateTime.MinValue;
bool _warned;
public DbIpLocator(IOptionsMonitor<StatisticsOptions> options, ILogger<DbIpLocator> logger)
{
_options = options;
_logger = logger;
}
public string Source
{
get
@@ -60,7 +54,8 @@ namespace PrivaPub.Infrastructure.Geo
if (address == default || !IpRangeGuard.IsPublic(address))
return default;
Refresh();
Dictionary<string, object> place, network;
var place = default(Dictionary<string, object>);
var network = default(Dictionary<string, object>);
try
{
// under the lock, so a reload cannot dispose a reader in the middle of a lookup; lookups are rare
@@ -82,7 +77,7 @@ namespace PrivaPub.Infrastructure.Geo
}
catch (Exception ex) when (ex is InvalidDatabaseException or ArgumentException)
{
_logger.LogWarning(ex, "The geolocation databases could not be read");
logger.LogWarning(ex, "The geolocation databases could not be read");
return default;
}
}
@@ -104,13 +99,13 @@ namespace PrivaPub.Infrastructure.Geo
if (DateTime.UtcNow - _checkedAt < CheckInterval)
return;
_checkedAt = DateTime.UtcNow;
var directory = _options.CurrentValue.GeoDirectory;
var directory = options.CurrentValue.GeoDirectory;
(_city, _cityStamp) = Open(Path.Combine(directory ?? string.Empty, CityFile), _city, _cityStamp);
(_asn, _asnStamp) = Open(Path.Combine(directory ?? string.Empty, AsnFile), _asn, _asnStamp);
if (_city == default && _asn == default && !_warned)
{
_warned = true;
_logger.LogInformation("No geolocation databases in {Directory}; servers are not located", directory);
logger.LogInformation("No geolocation databases in {Directory}; servers are not located", directory);
}
}
}
@@ -133,7 +128,7 @@ namespace PrivaPub.Infrastructure.Geo
}
catch (Exception ex) when (ex is InvalidDatabaseException or IOException)
{
_logger.LogWarning(ex, "{Path} is not a readable geolocation database", path);
logger.LogWarning(ex, "{Path} is not a readable geolocation database", path);
return (current, stamp);
}
}