remove dumps

This commit is contained in:
mrilyew 2025-06-26 16:17:45 +03:00
parent 9079df9646
commit 3e44516095
3 changed files with 23 additions and 41 deletions

View file

@ -34,7 +34,6 @@ trait TSubscribable
"target" => $this->getId(),
];
$sub = $ctx->table("subscriptions")->where($data);
if (!($sub->fetch())) {
$ctx->table("subscriptions")->insert($data);

View file

@ -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 = [];

View file

@ -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();