From 3e44516095fc3f2b2bba7996edb85841028ac09a Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Thu, 26 Jun 2025 16:17:45 +0300 Subject: [PATCH] remove dumps --- Web/Models/Entities/Traits/TSubscribable.php | 1 - Web/Models/Entities/User.php | 21 +++------- Web/Util/EventRateLimiter.php | 42 +++++++++----------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Web/Models/Entities/Traits/TSubscribable.php b/Web/Models/Entities/Traits/TSubscribable.php index 712b2366..2e3f3bcd 100644 --- a/Web/Models/Entities/Traits/TSubscribable.php +++ b/Web/Models/Entities/Traits/TSubscribable.php @@ -34,7 +34,6 @@ trait TSubscribable "target" => $this->getId(), ]; $sub = $ctx->table("subscriptions")->where($data); - if (!($sub->fetch())) { $ctx->table("subscriptions")->insert($data); diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index c31fe048..2f336f4a 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -114,7 +114,6 @@ class User extends RowModel public function getChandlerUser(): ChandlerUser { - # TODO cache this function return new ChandlerUser($this->getRecord()->ref("ChandlerUsers", "user")); } @@ -1747,17 +1746,13 @@ class User extends RowModel $counters = []; if (!$ev_str) { - bdump(sizeof(array_keys($list))); for ($i = 0; $i < sizeof(array_keys($list)); $i++) { $counters[] = 0; } } else { - $counters = unpack("S".$count_of_keys, base64_decode($ev_str, true)); - + $counters = unpack("S" . $count_of_keys, base64_decode($ev_str, true)); } - bdump(array_keys($list)); - bdump($counters); return [ 'counters' => array_combine(array_keys($list), $counters), 'refresh_time' => $this->getRecord()->events_refresh_time, @@ -1766,26 +1761,20 @@ class User extends RowModel public function stateEvents(array $state_list): void { - $_ = ""; - $i = 0; + $pack_str = ""; foreach ($state_list as $item => $id) { - bdump($i); - $_ .= "S"; - $i += 1; + $pack_str .= "S"; } - bdump($_); - bdump(array_values($state_list)); - - $this->stateChanges("events_counters", base64_encode(pack($_, ...array_values($state_list)))); + $this->stateChanges("events_counters", base64_encode(pack($pack_str, ...array_values($state_list)))); if (!$this->getRecord()->events_refresh_time) { $this->stateChanges("events_refresh_time", time()); } } - public function resetEvents(array $list) + public function resetEvents(array $list): void { $values = []; diff --git a/Web/Util/EventRateLimiter.php b/Web/Util/EventRateLimiter.php index 3257bc4e..cc71309f 100644 --- a/Web/Util/EventRateLimiter.php +++ b/Web/Util/EventRateLimiter.php @@ -19,22 +19,23 @@ class EventRateLimiter $this->config = OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["rateLimits"]["eventsLimit"]; } - /* - Checks count of actions for last x seconds. - - Uses OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["rateLimits"]["eventsLimit"] - - This check should be peformed only after checking other conditions cuz by default it increments counter - - Returns: - - true — limit has exceed and the action must be restricted - - false — the action can be performed - */ public function tryToLimit(?User $user, string $event_type, bool $is_update = true): bool { - bdump("TRY TO LIMIT IS CALLLLED"); + + /* + Checks count of actions for last x seconds. + + Uses OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["rateLimits"]["eventsLimit"] + + This check should be peformed only after checking other conditions cuz by default it increments counter + + Returns: + + true — limit has exceed and the action must be restricted + + false — the action can be performed + */ + $isEnabled = $this->config['enable']; $isIgnoreForAdmins = $this->config['ignoreForAdmins']; $restrictionTime = $this->config['restrictionTime']; @@ -54,12 +55,9 @@ class EventRateLimiter $counters = $eventsStats["counters"]; $refresh_time = $eventsStats["refresh_time"]; $is_restrict_over = $refresh_time < (time() - $restrictionTime); - bdump($refresh_time); - bdump("time: " . time()); $event_counter = $counters[$event_type]; if ($refresh_time && $is_restrict_over) { - bdump("RESETTING EVENT COUTNERS"); $user->resetEvents($eventsList); return false; @@ -67,7 +65,6 @@ class EventRateLimiter $is_limit_exceed = $event_counter >= $limitForThatEvent; - bdump($is_limit_exceed); if (!$is_limit_exceed && $is_update) { $this->incrementEvent($counters, $event_type, $user); } @@ -75,23 +72,20 @@ class EventRateLimiter return $is_limit_exceed; } - /* - Updates counter for user - */ public function incrementEvent(array $old_values, string $event_type, User $initiator): bool { - bdump("INCREMENT IS CALLED"); + /* + Updates counter for user + */ $isEnabled = $this->config['enable']; $eventsList = $this->config['list']; if (!$isEnabled) { return false; } - bdump($old_values); $old_values[$event_type] += 1; - bdump($old_values); $initiator->stateEvents($old_values); $initiator->save();