GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(usage): held accounts count down to the reset that frees them · pingdotgg/t3code@91ac573

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • usageLimits.test.ts
    • usageLimits.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/usageLimits.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/usageLimits.test.ts
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,22 @@ describe("pooled binding limits", () => {
11561156
});
11571157
});
11581158

1159-
it("restores nothing while another binding weekly is still spent", () => {
1159+
it("counts down to its own reset when a spent session outlasts its spent weekly", () => {
1160+
const [pool] = collectLimitPools(
1161+
[
1162+
account("A", [
1163+
{ ...window, usedPercent: 100, resetsAt: resetIn(240) },
1164+
{ ...weekly, usedPercent: 100, resetsAt: resetIn(60) },
1165+
]),
1166+
],
1167+
now,
1168+
);
1169+
const session = pool!.windows[0]!;
1170+
expect(session.members[0]).toMatchObject({ effectiveRemainingPercent: 0, holdingWindow: null });
1171+
expect(session.resets).toMatchObject([{ at: Date.parse(resetIn(240)), restoresPercent: 100 }]);
1172+
});
1173+
1174+
it("counts down to the last of several spent binding weeklies", () => {
11601175
const [pool] = collectLimitPools(
11611176
[
11621177
account(
@@ -1173,9 +1188,9 @@ describe("pooled binding limits", () => {
11731188
);
11741189
expect(pool!.windows[0]).toMatchObject({
11751190
remainingPercent: 0,
1176-
resets: [{ at: Date.parse(resetIn(120)), restoresPercent: 0 }],
1191+
members: [{ holdingWindow: { id: "other" } }],
1192+
resets: [{ at: Date.parse(resetIn(180)), restoresPercent: 100 }],
11771193
});
1178-
expect(pool!.windows[0]!.resets.find((reset) => reset.restoresPercent > 0)).toBeUndefined();
11791194
});
11801195
});
11811196

Collapse file

‎packages/shared/src/usageLimits.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/usageLimits.ts
+24-5Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export interface LimitPoolMember {
364364
readonly window: ServerProviderUsageWindow;
365365
/** Raw remaining quota, or zero while a broader allowance is used up. */
366366
readonly effectiveRemainingPercent: number;
367-
/** A broader allowance that is used up, or null when this window is unheld. */
367+
/** The used-up broader allowance whose reset frees this window, or null when none holds it. */
368368
readonly holdingWindow: ServerProviderUsageWindow | null;
369369
}
370370

@@ -514,11 +514,30 @@ function quotaRemaining(window: ServerProviderUsageWindow): number {
514514
return 100 - Math.max(0, Math.min(100, window.usedPercent));
515515
}
516516

517+
/**
518+
* The account spends again only once every used-up window has reset, so the
519+
* last of those resets is its countdown. A broader window holds it when it
520+
* is that last reset; a session that is spent past it holds itself.
521+
*/
517522
function poolMember(account: LimitAccount, window: ServerProviderUsageWindow): LimitPoolMember {
518-
const holdingWindow =
519-
bindingWindows(account, window).find((broader) => broader.usedPercent >= 100) ?? null;
520-
const effectiveRemainingPercent = holdingWindow ? 0 : quotaRemaining(window);
521-
return { account, window, effectiveRemainingPercent, holdingWindow };
523+
const lastReset = (w: ServerProviderUsageWindow) => resetMillis(w) ?? Number.POSITIVE_INFINITY;
524+
const spent = bindingWindows(account, window).filter((broader) => broader.usedPercent >= 100);
525+
if (spent.length === 0) {
526+
return {
527+
account,
528+
window,
529+
effectiveRemainingPercent: quotaRemaining(window),
530+
holdingWindow: null,
531+
};
532+
}
533+
const latest = spent.reduce((a, b) => (lastReset(b) > lastReset(a) ? b : a));
534+
const selfLater = window.usedPercent >= 100 && lastReset(window) > lastReset(latest);
535+
return {
536+
account,
537+
window,
538+
effectiveRemainingPercent: 0,
539+
holdingWindow: selfLater ? null : latest,
540+
};
522541
}
523542

524543
function poolWindows(accounts: readonly LimitAccount[], now: number): readonly LimitPoolWindow[] {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.