mirror of
https://github.com/openvk/openvk
synced 2025-07-03 06:19:49 +03:00
remove dumps
This commit is contained in:
parent
9079df9646
commit
3e44516095
3 changed files with 23 additions and 41 deletions
|
@ -34,7 +34,6 @@ trait TSubscribable
|
||||||
"target" => $this->getId(),
|
"target" => $this->getId(),
|
||||||
];
|
];
|
||||||
$sub = $ctx->table("subscriptions")->where($data);
|
$sub = $ctx->table("subscriptions")->where($data);
|
||||||
|
|
||||||
if (!($sub->fetch())) {
|
if (!($sub->fetch())) {
|
||||||
$ctx->table("subscriptions")->insert($data);
|
$ctx->table("subscriptions")->insert($data);
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,6 @@ class User extends RowModel
|
||||||
|
|
||||||
public function getChandlerUser(): ChandlerUser
|
public function getChandlerUser(): ChandlerUser
|
||||||
{
|
{
|
||||||
# TODO cache this function
|
|
||||||
return new ChandlerUser($this->getRecord()->ref("ChandlerUsers", "user"));
|
return new ChandlerUser($this->getRecord()->ref("ChandlerUsers", "user"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1747,17 +1746,13 @@ class User extends RowModel
|
||||||
$counters = [];
|
$counters = [];
|
||||||
|
|
||||||
if (!$ev_str) {
|
if (!$ev_str) {
|
||||||
bdump(sizeof(array_keys($list)));
|
|
||||||
for ($i = 0; $i < sizeof(array_keys($list)); $i++) {
|
for ($i = 0; $i < sizeof(array_keys($list)); $i++) {
|
||||||
$counters[] = 0;
|
$counters[] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} 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 [
|
return [
|
||||||
'counters' => array_combine(array_keys($list), $counters),
|
'counters' => array_combine(array_keys($list), $counters),
|
||||||
'refresh_time' => $this->getRecord()->events_refresh_time,
|
'refresh_time' => $this->getRecord()->events_refresh_time,
|
||||||
|
@ -1766,26 +1761,20 @@ class User extends RowModel
|
||||||
|
|
||||||
public function stateEvents(array $state_list): void
|
public function stateEvents(array $state_list): void
|
||||||
{
|
{
|
||||||
$_ = "";
|
$pack_str = "";
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
foreach ($state_list as $item => $id) {
|
foreach ($state_list as $item => $id) {
|
||||||
bdump($i);
|
$pack_str .= "S";
|
||||||
$_ .= "S";
|
|
||||||
$i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bdump($_);
|
$this->stateChanges("events_counters", base64_encode(pack($pack_str, ...array_values($state_list))));
|
||||||
bdump(array_values($state_list));
|
|
||||||
|
|
||||||
$this->stateChanges("events_counters", base64_encode(pack($_, ...array_values($state_list))));
|
|
||||||
|
|
||||||
if (!$this->getRecord()->events_refresh_time) {
|
if (!$this->getRecord()->events_refresh_time) {
|
||||||
$this->stateChanges("events_refresh_time", time());
|
$this->stateChanges("events_refresh_time", time());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetEvents(array $list)
|
public function resetEvents(array $list): void
|
||||||
{
|
{
|
||||||
$values = [];
|
$values = [];
|
||||||
|
|
||||||
|
|
|
@ -19,22 +19,23 @@ class EventRateLimiter
|
||||||
$this->config = OPENVK_ROOT_CONF["openvk"]["preferences"]["security"]["rateLimits"]["eventsLimit"];
|
$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
|
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'];
|
$isEnabled = $this->config['enable'];
|
||||||
$isIgnoreForAdmins = $this->config['ignoreForAdmins'];
|
$isIgnoreForAdmins = $this->config['ignoreForAdmins'];
|
||||||
$restrictionTime = $this->config['restrictionTime'];
|
$restrictionTime = $this->config['restrictionTime'];
|
||||||
|
@ -54,12 +55,9 @@ class EventRateLimiter
|
||||||
$counters = $eventsStats["counters"];
|
$counters = $eventsStats["counters"];
|
||||||
$refresh_time = $eventsStats["refresh_time"];
|
$refresh_time = $eventsStats["refresh_time"];
|
||||||
$is_restrict_over = $refresh_time < (time() - $restrictionTime);
|
$is_restrict_over = $refresh_time < (time() - $restrictionTime);
|
||||||
bdump($refresh_time);
|
|
||||||
bdump("time: " . time());
|
|
||||||
$event_counter = $counters[$event_type];
|
$event_counter = $counters[$event_type];
|
||||||
|
|
||||||
if ($refresh_time && $is_restrict_over) {
|
if ($refresh_time && $is_restrict_over) {
|
||||||
bdump("RESETTING EVENT COUTNERS");
|
|
||||||
$user->resetEvents($eventsList);
|
$user->resetEvents($eventsList);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -67,7 +65,6 @@ class EventRateLimiter
|
||||||
|
|
||||||
$is_limit_exceed = $event_counter >= $limitForThatEvent;
|
$is_limit_exceed = $event_counter >= $limitForThatEvent;
|
||||||
|
|
||||||
bdump($is_limit_exceed);
|
|
||||||
if (!$is_limit_exceed && $is_update) {
|
if (!$is_limit_exceed && $is_update) {
|
||||||
$this->incrementEvent($counters, $event_type, $user);
|
$this->incrementEvent($counters, $event_type, $user);
|
||||||
}
|
}
|
||||||
|
@ -75,23 +72,20 @@ class EventRateLimiter
|
||||||
return $is_limit_exceed;
|
return $is_limit_exceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Updates counter for user
|
|
||||||
*/
|
|
||||||
public function incrementEvent(array $old_values, string $event_type, User $initiator): bool
|
public function incrementEvent(array $old_values, string $event_type, User $initiator): bool
|
||||||
{
|
{
|
||||||
bdump("INCREMENT IS CALLED");
|
/*
|
||||||
|
Updates counter for user
|
||||||
|
*/
|
||||||
$isEnabled = $this->config['enable'];
|
$isEnabled = $this->config['enable'];
|
||||||
$eventsList = $this->config['list'];
|
$eventsList = $this->config['list'];
|
||||||
|
|
||||||
if (!$isEnabled) {
|
if (!$isEnabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bdump($old_values);
|
|
||||||
|
|
||||||
$old_values[$event_type] += 1;
|
$old_values[$event_type] += 1;
|
||||||
|
|
||||||
bdump($old_values);
|
|
||||||
$initiator->stateEvents($old_values);
|
$initiator->stateEvents($old_values);
|
||||||
$initiator->save();
|
$initiator->save();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue