Usage_Limits
Per-visitor rate limit and site-wide daily cap.
Visitors are identified by a salted hash of their IP address. The hash is only used in the name of an hourly counter, deleted once a later window starts, and is never logged.
Counters are options updated with a single SQL statement, so concurrent requests cannot lose increments or overshoot a limit.
Namespace: WebberZone\Better_Search\Pro\AI
Since: 4.5.0
Source: includes/pro/ai/class-usage-limits.php line 25
Methods
get_visitor_key() static
Key identifying the current visitor.
Since: 4.5.0
Line: 48
static public function get_visitor_key( ): string;
Returns: string — Visitor key.
is_visitor_limited() static
Whether a visitor has used up their questions for the current window.
Since: 4.5.0
Line: 73
static public function is_visitor_limited( string $visitor_key ): bool;
| Type | Name | Description |
|---|---|---|
string |
$visitor_key |
Visitor key. |
Returns: bool — True if limited.
reserve_visitor() static
Count a question against a visitor, if they have questions left.
Since: 4.5.0
Line: 85
static public function reserve_visitor( string $visitor_key ): bool;
| Type | Name | Description |
|---|---|---|
string |
$visitor_key |
Visitor key. |
Returns: bool — True if the question is within the limit.
get_retry_after() static
Seconds until the current rate-limit window resets.
Since: 4.5.0
Line: 104
static public function get_retry_after( string $visitor_key ): int;
| Type | Name | Description |
|---|---|---|
string |
$visitor_key |
Visitor key. |
Returns: int — Seconds.
mark_question() static
Record that a visitor asked a question in the current window.
Cached answers don’t count towards the limits, so this stops one visitor repeating a question to inflate the question log.
Since: 4.5.0
Line: 120
static public function mark_question( string $visitor_key, string $question ): bool;
| Type | Name | Description |
|---|---|---|
string |
$visitor_key |
Visitor key. |
string |
$question |
Question. |
Returns: bool — True the first time the visitor asks the question in the window, false for a repeat.
get_visitor_limit() static
Per-visitor limit per hour.
Since: 4.5.0
Line: 139
static public function get_visitor_limit( ): int;
Returns: int — Limit.
is_daily_cap_reached() static
Whether the site has reached today’s provider request cap.
Since: 4.5.0
Line: 150
static public function is_daily_cap_reached( ): bool;
Returns: bool — True if reached.
get_daily_count() static
Provider requests made today (site time).
Since: 4.5.0
Line: 161
static public function get_daily_count( ): int;
Returns: int — Count.
reserve_provider_request() static
Reserve a provider request against today’s cap.
Since: 4.5.0
Line: 172
static public function reserve_provider_request( ): bool;
Returns: bool — True if reserved, false if the cap is reached.
record_provider_request() static
Count a provider request against today’s cap, whether or not it is reached.
Since: 4.5.0
Line: 198
static public function record_provider_request( ): void;
Returns: void
get_daily_cap() static
Daily provider request cap.
Since: 4.5.0
Line: 209
static public function get_daily_cap( ): int;
Returns: int — Cap.