File size: 1,122 Bytes
ddebc3e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """AccountLease — minimal hot-path rental object."""
from dataclasses import dataclass
from app.platform.runtime.ids import next_id
@dataclass(slots=True)
class AccountLease:
"""Represents a reserved account slot for a single upstream request.
Holds only the minimum fields needed on the hot path — no AccountRecord.
The slot *idx* allows O(1) array access for feedback updates.
"""
lease_id: int # monotonic counter — cheaper than uuid
idx: int # slot in AccountRuntimeTable
token: str # cached for header building
pool_id: int # PoolId integer
mode_id: int # ModeId integer
selected_at: int # ms timestamp
def new_lease(idx: int, token: str, pool_id: int, mode_id: int, selected_at: int) -> AccountLease:
"""Construct an AccountLease with an auto-incremented id."""
return AccountLease(
lease_id = next_id(),
idx = idx,
token = token,
pool_id = pool_id,
mode_id = mode_id,
selected_at = selected_at,
)
__all__ = ["AccountLease", "new_lease"]
|