Skip to content

Commit 304832e

Browse files
authored
fix and speed up migration of 'last_boosted_at' column (#2184)
1 parent f5fd5c6 commit 304832e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

migrations/Version20260526175316.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ public function down(Schema $schema): void
4141
public function postUp(Schema $schema): void
4242
{
4343
$this->connection->transactional(function (): void {
44-
$sqlTpl = 'UPDATE $e SET last_boosted_at = greatest((SELECT $e_vote.created_at FROM $e_vote WHERE $e_vote.$fk = $e.id ORDER BY $e_vote.created_at DESC LIMIT 1), created_at);';
44+
$sqlTpl = 'UPDATE $e SET last_boosted_at = greatest((SELECT $e_vote.created_at FROM $e_vote WHERE $e_vote.$fk = $e.id AND choice = 1 ORDER BY $e_vote.created_at DESC LIMIT 1), created_at);';
4545
$this->connection->executeStatement(str_replace('$e', 'entry', str_replace('$fk', 'entry_id', $sqlTpl)));
46-
$this->connection->executeStatement(str_replace('$e', 'entry_comment', str_replace('$fk', 'comment_id', $sqlTpl)));
4746
$this->connection->executeStatement(str_replace('$e', 'post', str_replace('$fk', 'post_id', $sqlTpl)));
4847
$this->connection->executeStatement(str_replace('$e', 'post_comment', str_replace('$fk', 'comment_id', $sqlTpl)));
48+
49+
// set last_boosted_at of entry_comment to its created_at time to speed up migrations; not may comments are boosted anyway
50+
$this->connection->executeStatement('UPDATE entry_comment SET last_boosted_at = created_at;');
4951
});
5052
}
5153
}

0 commit comments

Comments
 (0)