MediaWiki REL1_39
Wikimedia\WRStats\WRStatsRateLimiter Class Reference

A rate limiter with a WRStats backend. More...

Public Member Functions

 __construct (StatsStore $store, $conditions, $prefix='WRLimit', $options=[])
 
 createBatch ( $defaultAmount=1)
 Create a batch object for rate limiting of multiple metrics.
 
 incr (string $condName, EntityKey $entityKey=null, $amount=1)
 Unconditionally increment a metric.
 
 incrBatch (array $operations)
 Unconditionally increment a set of metrics.
 
 peek (string $condName, EntityKey $entityKey=null, $amount=1)
 Check whether executing a single operation would exceed the defined limit, without incrementing the count.
 
 peekBatch (array $operations)
 Check whether executing a given set of increment operations would exceed any defined limit, without actually performing the increment.
 
 resetCurrentTime ()
 Forget a time set with setCurrentTime().
 
 setCurrentTime ( $now)
 Set the current time.
 
 tryIncr (string $condName, EntityKey $entityKey=null, $amount=1)
 Check if the limit would be exceeded by incrementing the specified metric.
 
 tryIncrBatch (array $operations)
 Check if the limit would be exceeded by execution of the given set of increment operations.
 

Public Attributes

const BUCKET_COUNT = 30
 Default number of time buckets per action.
 

Detailed Description

A rate limiter with a WRStats backend.

Definition at line 8 of file WRStatsRateLimiter.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\WRStats\WRStatsRateLimiter::__construct ( StatsStore $store,
$conditions,
$prefix = 'WRLimit',
$options = [] )
Access: internal
Use WRStatsFactory
See also
WRStatsFactory::createRateLimiter for full parameter documentation.
Parameters
StatsStore$store
LimitCondition[]$conditions
string | string[]$prefix
array$options

Definition at line 33 of file WRStatsRateLimiter.php.

References Wikimedia\WRStats\WRStatsRateLimiter\BUCKET_COUNT.

Member Function Documentation

◆ createBatch()

Wikimedia\WRStats\WRStatsRateLimiter::createBatch ( $defaultAmount = 1)

Create a batch object for rate limiting of multiple metrics.

Parameters
int$defaultAmountThe amount to increment each metric by, if no amount is passed to localOp/globalOp
Returns
LimitBatch

Definition at line 63 of file WRStatsRateLimiter.php.

◆ incr()

Wikimedia\WRStats\WRStatsRateLimiter::incr ( string $condName,
EntityKey $entityKey = null,
$amount = 1 )

Unconditionally increment a metric.

Parameters
string$condName
EntityKey | null$entityKey
int$amount
Returns
void

Definition at line 172 of file WRStatsRateLimiter.php.

◆ incrBatch()

Wikimedia\WRStats\WRStatsRateLimiter::incrBatch ( array $operations)

Unconditionally increment a set of metrics.

Parameters
LimitOperation[]$operations

Definition at line 186 of file WRStatsRateLimiter.php.

◆ peek()

Wikimedia\WRStats\WRStatsRateLimiter::peek ( string $condName,
EntityKey $entityKey = null,
$amount = 1 )

Check whether executing a single operation would exceed the defined limit, without incrementing the count.

Parameters
string$condName
EntityKey | null$entityKey
int$amount
Returns
LimitOperationResult

Definition at line 76 of file WRStatsRateLimiter.php.

◆ peekBatch()

Wikimedia\WRStats\WRStatsRateLimiter::peekBatch ( array $operations)

Check whether executing a given set of increment operations would exceed any defined limit, without actually performing the increment.

Parameters
LimitOperation[]$operations
Returns
LimitBatchResult

Definition at line 93 of file WRStatsRateLimiter.php.

◆ resetCurrentTime()

Wikimedia\WRStats\WRStatsRateLimiter::resetCurrentTime ( )

Forget a time set with setCurrentTime().

Use the actual current time.

Definition at line 213 of file WRStatsRateLimiter.php.

◆ setCurrentTime()

Wikimedia\WRStats\WRStatsRateLimiter::setCurrentTime ( $now)

Set the current time.

Parameters
float | int$now

Definition at line 206 of file WRStatsRateLimiter.php.

◆ tryIncr()

Wikimedia\WRStats\WRStatsRateLimiter::tryIncr ( string $condName,
EntityKey $entityKey = null,
$amount = 1 )

Check if the limit would be exceeded by incrementing the specified metric.

If not, increment it.

Parameters
string$condName
EntityKey | null$entityKey
int$amount
Returns
LimitOperationResult

Definition at line 139 of file WRStatsRateLimiter.php.

◆ tryIncrBatch()

Wikimedia\WRStats\WRStatsRateLimiter::tryIncrBatch ( array $operations)

Check if the limit would be exceeded by execution of the given set of increment operations.

If not, perform the increments.

Parameters
LimitOperation[]$operations
Returns
LimitBatchResult

Definition at line 156 of file WRStatsRateLimiter.php.

Member Data Documentation

◆ BUCKET_COUNT

const Wikimedia\WRStats\WRStatsRateLimiter::BUCKET_COUNT = 30

Default number of time buckets per action.

Definition at line 21 of file WRStatsRateLimiter.php.

Referenced by Wikimedia\WRStats\WRStatsRateLimiter\__construct().


The documentation for this class was generated from the following file: