Improved performance of "hide downvoted"

This commit is contained in:
Marcin Kurczewski 2014-10-20 20:15:45 +02:00
parent 88dfc0eb96
commit 20d75e177d
4 changed files with 18 additions and 6 deletions

View file

@ -156,15 +156,15 @@ class PostDao extends AbstractDao implements ICrudDao
$values = $requirement->getValue()->getValues(); $values = $requirement->getValue()->getValues();
$userName = $values[0]; $userName = $values[0];
$score = $values[1]; $score = $values[1];
$userId = $this->userDao->findByName($userName)->getId();
$sql = 'EXISTS ( $sql = 'EXISTS (
SELECT 1 FROM scores SELECT 1 FROM scores
INNER JOIN users ON scores.userId = users.id
WHERE scores.postId = posts.id WHERE scores.postId = posts.id
AND LOWER(users.name) = LOWER(?) AND scores.userId = ?
AND scores.score = ?)'; AND scores.score = ?)';
if ($requirement->isnegated()) if ($requirement->isNegated())
$sql = 'NOT ' . $sql; $sql = 'NOT ' . $sql;
$query->where($sql, [$userName, $score]); $query->where($sql, [$userId, $score]);
return; return;
} }

View file

@ -7,8 +7,6 @@ class Upgrade25 implements IUpgrade
public function run(DatabaseConnection $databaseConnection) public function run(DatabaseConnection $databaseConnection)
{ {
$pdo = $databaseConnection->getPDO(); $pdo = $databaseConnection->getPDO();
$pdo->exec('ALTER TABLE tags ADD COLUMN category VARCHAR(25)'); $pdo->exec('ALTER TABLE tags ADD COLUMN category VARCHAR(25)');
} }
} }

View file

@ -0,0 +1,13 @@
<?php
namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade26 implements IUpgrade
{
public function run(DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$pdo->exec('CREATE INDEX idx_scores_commentId ON scores(commentId)');
$pdo->exec('CREATE INDEX idx_scores_postId ON scores(postId)');
}
}

View file

@ -41,6 +41,7 @@ return [
$container->get(\Szurubooru\Upgrades\Upgrade23::class), $container->get(\Szurubooru\Upgrades\Upgrade23::class),
$container->get(\Szurubooru\Upgrades\Upgrade24::class), $container->get(\Szurubooru\Upgrades\Upgrade24::class),
$container->get(\Szurubooru\Upgrades\Upgrade25::class), $container->get(\Szurubooru\Upgrades\Upgrade25::class),
$container->get(\Szurubooru\Upgrades\Upgrade26::class),
]; ];
}), }),