Changed global comment list sort to creation time

Before this change, it was using edit time, which resulted in bumping
old posts every time a comment was edited. Users reported this behavior
as awkward and unintuitive, so I've changed it.
This commit is contained in:
rr- 2015-11-24 15:37:16 +01:00
parent f5aed19bf3
commit 645573a272
4 changed files with 55 additions and 2 deletions

View file

@ -11,7 +11,7 @@ class PostFilter extends BasicFilter implements IFilter
const ORDER_SCORE = 'score';
const ORDER_LAST_EDIT_TIME = 'lastEditTime';
const ORDER_FILE_SIZE = 'originalFileSize';
const ORDER_LAST_COMMENT_TIME = 'lastCommentTime';
const ORDER_LAST_COMMENT_TIME = 'lastCommentCreationTime';
const ORDER_LAST_FAV_TIME = 'lastFavTime';
const ORDER_LAST_FEATURE_TIME = 'lastFeatureTime';

View file

@ -7,7 +7,6 @@ class Upgrade41 implements IUpgrade
public function run(DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver();
$pdo->exec('
CREATE TRIGGER postNotesDelete AFTER DELETE ON postNotes

View file

@ -0,0 +1,53 @@
<?php
namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade42 implements IUpgrade
{
public function run(DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$pdo->exec('ALTER TABLE posts CHANGE COLUMN lastCommentTime lastCommentEditTime TIMESTAMP NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE posts ADD COLUMN lastCommentCreationTime TIMESTAMP NOT NULL DEFAULT 0');
$pdo->exec('DROP TRIGGER IF EXISTS commentsDelete');
$pdo->exec('DROP TRIGGER IF EXISTS commentsInsert');
$pdo->exec('DROP TRIGGER IF EXISTS commentsUpdate');
$pdo->exec('
CREATE TRIGGER commentsDelete AFTER DELETE ON comments
FOR EACH ROW
BEGIN
UPDATE posts SET
commentCount = (SELECT COUNT(1) FROM comments WHERE comments.postId = posts.id),
lastCommentCreationTime = (SELECT MAX(creationTime) FROM comments WHERE comments.postId = posts.id),
lastCommentEditTime = (SELECT MAX(lastEditTime) FROM comments WHERE comments.postId = posts.id)
WHERE posts.id = OLD.postId;
END');
$pdo->exec('
CREATE TRIGGER commentsInsert AFTER INSERT ON comments
FOR EACH ROW
BEGIN
UPDATE posts SET
commentCount = (SELECT COUNT(1) FROM comments WHERE comments.postId = posts.id),
lastCommentCreationTime = (SELECT MAX(creationTime) FROM comments WHERE comments.postId = posts.id),
lastCommentEditTime = (SELECT MAX(lastEditTime) FROM comments WHERE comments.postId = posts.id)
WHERE posts.id = NEW.postId;
END');
$pdo->exec('
CREATE TRIGGER commentsUpdate AFTER UPDATE ON comments
FOR EACH ROW
BEGIN
UPDATE posts SET
commentCount = (SELECT COUNT(1) FROM comments WHERE comments.postId = posts.id),
lastCommentCreationTime = (SELECT MAX(creationTime) FROM comments WHERE comments.postId = posts.id),
lastCommentEditTime = (SELECT MAX(lastEditTime) FROM comments WHERE comments.postId = posts.id)
WHERE posts.id IN (OLD.postId, NEW.postId);
END');
$pdo->exec('UPDATE posts SET lastCommentCreationTime = (SELECT MAX(creationTime) FROM comments WHERE comments.postId = posts.id)');
}
}

View file

@ -58,6 +58,7 @@ return [
$container->get(\Szurubooru\Upgrades\Upgrade39::class),
$container->get(\Szurubooru\Upgrades\Upgrade40::class),
$container->get(\Szurubooru\Upgrades\Upgrade41::class),
$container->get(\Szurubooru\Upgrades\Upgrade42::class),
];
}),