diff --git a/src/Dao/PostDao.php b/src/Dao/PostDao.php index 70ff3d39..e24e7ee2 100644 --- a/src/Dao/PostDao.php +++ b/src/Dao/PostDao.php @@ -156,15 +156,15 @@ class PostDao extends AbstractDao implements ICrudDao $values = $requirement->getValue()->getValues(); $userName = $values[0]; $score = $values[1]; + $userId = $this->userDao->findByName($userName)->getId(); $sql = 'EXISTS ( SELECT 1 FROM scores - INNER JOIN users ON scores.userId = users.id WHERE scores.postId = posts.id - AND LOWER(users.name) = LOWER(?) + AND scores.userId = ? AND scores.score = ?)'; - if ($requirement->isnegated()) + if ($requirement->isNegated()) $sql = 'NOT ' . $sql; - $query->where($sql, [$userName, $score]); + $query->where($sql, [$userId, $score]); return; } diff --git a/src/Upgrades/Upgrade25.php b/src/Upgrades/Upgrade25.php index 0019dad9..ee3ef53d 100644 --- a/src/Upgrades/Upgrade25.php +++ b/src/Upgrades/Upgrade25.php @@ -7,8 +7,6 @@ class Upgrade25 implements IUpgrade public function run(DatabaseConnection $databaseConnection) { $pdo = $databaseConnection->getPDO(); - $pdo->exec('ALTER TABLE tags ADD COLUMN category VARCHAR(25)'); } } - diff --git a/src/Upgrades/Upgrade26.php b/src/Upgrades/Upgrade26.php new file mode 100644 index 00000000..9d14f159 --- /dev/null +++ b/src/Upgrades/Upgrade26.php @@ -0,0 +1,13 @@ +getPDO(); + $pdo->exec('CREATE INDEX idx_scores_commentId ON scores(commentId)'); + $pdo->exec('CREATE INDEX idx_scores_postId ON scores(postId)'); + } +} diff --git a/src/di.php b/src/di.php index 9e1c3244..9de1121d 100644 --- a/src/di.php +++ b/src/di.php @@ -41,6 +41,7 @@ return [ $container->get(\Szurubooru\Upgrades\Upgrade23::class), $container->get(\Szurubooru\Upgrades\Upgrade24::class), $container->get(\Szurubooru\Upgrades\Upgrade25::class), + $container->get(\Szurubooru\Upgrades\Upgrade26::class), ]; }),