Browse Source

Simplified query "Topics with your posts", part of the logic moved to php, for large forums

Visman 1 year ago
parent
commit
62fd33bec2
1 changed files with 16 additions and 1 deletions
  1. 16 1
      app/Models/Search/ActionT.php

+ 16 - 1
app/Models/Search/ActionT.php

@@ -68,12 +68,19 @@ class ActionT extends Method
 
 
                 break;
                 break;
             case 'topics_with_your_posts':
             case 'topics_with_your_posts':
+/*
                 $query = 'SELECT t.id
                 $query = 'SELECT t.id
                     FROM ::topics AS t
                     FROM ::topics AS t
                     INNER JOIN ::posts AS p ON t.id=p.topic_id
                     INNER JOIN ::posts AS p ON t.id=p.topic_id
                     WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid
                     WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid
                     GROUP BY t.id
                     GROUP BY t.id
                     ORDER BY t.last_post DESC';
                     ORDER BY t.last_post DESC';
+*/
+                // упрощенный запрос для больших форумов, дополнительная обработка ниже
+                $query = 'SELECT DISTINCT t.id, t.last_post
+                    FROM forum_topics AS t
+                    INNER JOIN forum_posts AS p ON t.id=p.topic_id
+                    WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid';
 
 
                 break;
                 break;
             case 'topics':
             case 'topics':
@@ -125,7 +132,15 @@ class ActionT extends Method
                 ':max'    => \max((int) $this->c->user->last_visit, (int) $this->c->user->u_mark_all_read),
                 ':max'    => \max((int) $this->c->user->last_visit, (int) $this->c->user->u_mark_all_read),
             ];
             ];
 
 
-            $list = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
+            if ('topics_with_your_posts' === $action) {
+                $list = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_KEY_PAIR);
+
+                \arsort($list, \SORT_NUMERIC);
+
+                $list = \array_keys($list);
+            } else {
+                $list = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
+            }
         }
         }
 
 
         $this->model->numPages = (int) \ceil(($this->model->count($list) ?: 1) / $this->c->user->disp_topics);
         $this->model->numPages = (int) \ceil(($this->model->count($list) ?: 1) / $this->c->user->disp_topics);