Files
decePubClient/Services/RequestStats.cs
T
thepraandClaude Opus 5.5 fd2f2e7c65
Build / Build (push) Successful in 51s
R1 cleanup: collAnon and dead code gone, no IndexedDB, honest PWA files
Starts the completion program (SocialPub docs/ROADMAP.md, "Owner decisions on finishing everything", 2026-10-17).

- The localizer's namespace is decePubClient.Services; collAnon is gone from the repo.
- Dead code: PagesBase, VConstants, SettingsOptions, ViewLanguage, unused APIs routes, InstanceService.Self,
  RequestStats.LastOf/AverageMs, PostAnon/DeleteTotallyAnon, unused AppStatusService methods and their main.js helpers
  (the app badge stays for Web Push), ExtensionMethods/SUtility leftovers (Markdig and BlazorZXingJs packages go),
  unused PublicCacheData/PageSettings/AppConfiguration fields, commented-out code.
- The client log in IndexedDB, which nothing ever read, goes with the whole IndexedDB layer (DnetIndexedDb, IStorage):
  logs go to the browser console; main.js deletes the old "data" database once.
- The solution names the real ClientModels project. Unused vendor assets (fontawesome, solid, open-iconic, rxjs) go.
- robots.txt disallows everything; manifest.json and index.html say decePub; the service worker's cache name follows
  each publish's assets version, so old caches are purged.
- MessageType is Visibility (member names kept: they are resx keys); ExpandMessage.razor is Thread.razor (same route).
- i18n: dead keys removed, Italian "camera" is "punto di vista", DInputBase/DCalendar validation messages come from
  ErrorMessages, DataTransfer's spinner has its label.
- CLAUDE.md follows: client storage, JS interop, PWA, the D fields' messages.

Verified: dotnet build decePubClient.csproj and decePubClient.sln -c Release (0 errors, no new warnings); a Pasture
publish served by the pasture's decepub peer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WpVCoDeM1qUTRp4fXQdfof
2026-10-17 02:56:57 +02:00

61 lines
1.8 KiB
C#

using System.Text.RegularExpressions;
namespace decePubClient.Services
{
/// <summary>One request HttpService sent, for the nerd stats.</summary>
public sealed record RequestStat(DateTime At, string Method, string Route, int Status, double DurationMs, long? Bytes,
int? RateLimitRemaining, DateTime? RateLimitReset);
/// <summary>
/// The last requests HttpService sent (a ring of Capacity entries), with route templates instead of ids. It holds no
/// bodies and no tokens: method, route, status, duration, size and PrivaPub's rate limit headers only.
/// </summary>
public partial class RequestStats
{
public const int Capacity = 200;
readonly RequestStat[] ring = new RequestStat[Capacity];
int next;
int count;
public event Action Recorded;
public int Count => count;
public void Record(RequestStat stat)
{
lock (ring)
{
ring[next] = stat;
next = (next + 1) % Capacity;
count = Math.Min(count + 1, Capacity);
}
Recorded?.Invoke();
}
/// <summary>The recorded requests, newest first.</summary>
public List<RequestStat> Latest(int take = Capacity)
{
lock (ring)
{
var latest = new List<RequestStat>(Math.Min(take, count));
for (var i = 1; i <= Math.Min(take, count); i++)
latest.Add(ring[(next - i + Capacity) % Capacity]);
return latest;
}
}
/// <summary>The route without its query, with ids replaced by :id, so requests to the same endpoint group.</summary>
public static string Template(string uri)
{
var path = uri?.Split('?', 2)[0] ?? string.Empty;
if (Uri.TryCreate(path, UriKind.Absolute, out var absolute))
path = absolute.AbsolutePath.TrimStart('/');
return Id().Replace(path, "/:id$1");
}
[GeneratedRegex(@"/(?:[0-9a-f]{24}|[0-9a-f]{32}|\d{6,}|[0-9A-Za-z_-]{20,})(/|$)")]
private static partial Regex Id();
}
}