Browse Source

Maybe make fewer updates for online table?

Visman 2 years ago
parent
commit
af462633cf
2 changed files with 17 additions and 2 deletions
  1. 15 0
      app/Models/Online/Online.php
  2. 2 2
      app/Models/User/Current.php

+ 15 - 0
app/Models/Online/Online.php

@@ -205,6 +205,21 @@ class Online extends Model
      */
     protected function updateUser(string $position): void
     {
+        // Может быть делать меньше обновлений?
+        if ($this->c->user->logged > 0) {
+            $diff = \time() - $this->c->user->logged;
+
+            if (
+                $diff < 5
+                || (
+                    $position === $this->c->user->o_position
+                    && $diff < $this->c->config->i_timeout_online / 10
+                )
+            ) {
+                return;
+            }
+        }
+
         // гость
         if ($this->c->user->isGuest) {
             $vars = [

+ 2 - 2
app/Models/User/Current.php

@@ -75,7 +75,7 @@ class Current extends Action
             $vars = [
                 ':id' => $id,
             ];
-            $query = 'SELECT u.*, g.*, o.logged
+            $query = 'SELECT u.*, g.*, o.logged, o.o_position
                 FROM ::users AS u
                 INNER JOIN ::groups AS g ON u.group_id=g.g_id
                 LEFT JOIN ::online AS o ON o.user_id=u.id
@@ -88,7 +88,7 @@ class Current extends Action
             $vars = [
                 ':ip' => $ip,
             ];
-            $query = 'SELECT o.logged, o.last_post, o.last_search
+            $query = 'SELECT o.logged, o.last_post, o.last_search, o.o_position
                 FROM ::online AS o
                 WHERE o.user_id=0 AND o.ident=?s:ip';