Browse Source

Replace index (with composite)

Visman 1 year ago
parent
commit
d18ec05c37

+ 1 - 1
app/Models/Forum/LoadTree.php

@@ -126,8 +126,8 @@ class LoadTree extends Action
             FROM ::topics AS t
             LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND mot.tid=t.id)
             WHERE t.forum_id IN(?ai:forums)
-                AND t.last_post>?i:max
                 AND t.moved_to=0
+                AND t.last_post>?i:max
                 AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)';
 
         $stmt = $this->c->DB->query($query, $vars);

+ 1 - 1
app/Models/Pages/Admin/Install.php

@@ -1053,9 +1053,9 @@ class Install extends Admin
             'PRIMARY KEY' => ['id'],
             'INDEXES' => [
                 'forum_id_idx'      => ['forum_id'],
-                'moved_to_idx'      => ['moved_to'],
                 'last_post_idx'     => ['last_post'],
                 'first_post_id_idx' => ['first_post_id'],
+                'multi_1_idx'       => ['moved_to', 'forum_id', 'num_replies'],
             ],
             'ENGINE' => $this->DBEngine,
         ];

+ 3 - 0
app/Models/Pages/Admin/Update.php

@@ -886,6 +886,9 @@ class Update extends Admin
 
         $this->c->DB->addIndex('::posts', 'editor_id_idx', ['editor_id']);
 
+        $this->c->DB->dropIndex('::topics', 'moved_to_idx');
+        $this->c->DB->addIndex('::topics', 'multi_1_idx', ['moved_to', 'forum_id', 'num_replies']);
+
         return null;
     }
 }

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

@@ -90,8 +90,8 @@ class ActionT extends Method
                     LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND mot.tid=t.id)
                     LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND mof.fid=t.forum_id)
                     WHERE t.forum_id IN (?ai:forums)
-                        AND t.last_post>?i:max
                         AND t.moved_to=0
+                        AND t.last_post>?i:max
                         AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)
                         AND (mof.mf_mark_all_read IS NULL OR t.last_post>mof.mf_mark_all_read)
                     ORDER BY t.last_post DESC';