Changeset View
Changeset View
Standalone View
Standalone View
support/startup/PhabricatorClientLimit.php
| Show First 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | private function addScore($score) { | ||||
| $client_key = $this->getClientKey(); | $client_key = $this->getClientKey(); | ||||
| if (empty($bucket[$client_key])) { | if (empty($bucket[$client_key])) { | ||||
| $bucket[$client_key] = 0; | $bucket[$client_key] = 0; | ||||
| } | } | ||||
| $bucket[$client_key] += $score; | $bucket[$client_key] += $score; | ||||
| if ($is_apcu) { | if ($is_apcu) { | ||||
| apcu_store($bucket_key, $bucket); | @apcu_store($bucket_key, $bucket); | ||||
| } else { | } else { | ||||
| apc_store($bucket_key, $bucket); | @apc_store($bucket_key, $bucket); | ||||
| } | } | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the current rate limit score for a given client. | * Get the current rate limit score for a given client. | ||||
| Show All 12 Lines | if ($is_apcu) { | ||||
| $min = apc_fetch($min_key); | $min = apc_fetch($min_key); | ||||
| } | } | ||||
| // If we don't have any buckets stored yet, store the current bucket as | // If we don't have any buckets stored yet, store the current bucket as | ||||
| // the oldest bucket. | // the oldest bucket. | ||||
| $cur = $this->getCurrentBucketID(); | $cur = $this->getCurrentBucketID(); | ||||
| if (!$min) { | if (!$min) { | ||||
| if ($is_apcu) { | if ($is_apcu) { | ||||
| apcu_store($min_key, $cur); | @apcu_store($min_key, $cur); | ||||
| } else { | } else { | ||||
| apc_store($min_key, $cur); | @apc_store($min_key, $cur); | ||||
| } | } | ||||
| $min = $cur; | $min = $cur; | ||||
| } | } | ||||
| // Destroy any buckets that are older than the minimum bucket we're keeping | // Destroy any buckets that are older than the minimum bucket we're keeping | ||||
| // track of. Under load this normally shouldn't do anything, but will clean | // track of. Under load this normally shouldn't do anything, but will clean | ||||
| // up an old bucket once per minute. | // up an old bucket once per minute. | ||||
| $count = $this->getBucketCount(); | $count = $this->getBucketCount(); | ||||
| for ($cursor = $min; $cursor < ($cur - $count); $cursor++) { | for ($cursor = $min; $cursor < ($cur - $count); $cursor++) { | ||||
| $bucket_key = $this->getBucketCacheKey($cursor); | $bucket_key = $this->getBucketCacheKey($cursor); | ||||
| if ($is_apcu) { | if ($is_apcu) { | ||||
| apcu_delete($bucket_key); | apcu_delete($bucket_key); | ||||
| apcu_store($min_key, $cursor + 1); | @apcu_store($min_key, $cursor + 1); | ||||
| } else { | } else { | ||||
| apc_delete($bucket_key); | apc_delete($bucket_key); | ||||
| apc_store($min_key, $cursor + 1); | @apc_store($min_key, $cursor + 1); | ||||
| } | } | ||||
| } | } | ||||
| $client_key = $this->getClientKey(); | $client_key = $this->getClientKey(); | ||||
| // Now, sum up the client's scores in all of the active buckets. | // Now, sum up the client's scores in all of the active buckets. | ||||
| $score = 0; | $score = 0; | ||||
| for (; $cursor <= $cur; $cursor++) { | for (; $cursor <= $cur; $cursor++) { | ||||
| Show All 15 Lines | |||||