From dad4b5b5edffde878367a7014e67b4dbb3f59433 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 30 Sep 2015 00:45:08 +0200 Subject: [PATCH] Update comments management, add index to releases.gid for better comment load speed in admin area. --- newznab/build/newznab.xml | 4 +- newznab/controllers/ReleaseComments.php | 24 +++---- resources/db/patches/0189~releases.sql | 1 + www/admin/comments-delete.php | 6 +- www/admin/comments-list.php | 12 ++-- .../views/admin/comments-list.tpl | 67 +++++++++---------- 6 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 resources/db/patches/0189~releases.sql diff --git a/newznab/build/newznab.xml b/newznab/build/newznab.xml index b8f44e6be..2b8eb496c 100644 --- a/newznab/build/newznab.xml +++ b/newznab/build/newznab.xml @@ -2,8 +2,8 @@ - 188 - 188 + 189 + 189 0.4.1 diff --git a/newznab/controllers/ReleaseComments.php b/newznab/controllers/ReleaseComments.php index eea8e0a25..c56bcb800 100644 --- a/newznab/controllers/ReleaseComments.php +++ b/newznab/controllers/ReleaseComments.php @@ -86,14 +86,13 @@ class ReleaseComments } /** - * Delete a comment. + * Delete single comment on the site. */ public function deleteComment($id) { $res = $this->getCommentById($id); - if ($res) - { - $this->pdo->queryExec(sprintf("update release_comments SET isvisible = 0 WHERE id = %d", $id)); + if ($res) { + $this->pdo->queryExec(sprintf("DELETE FROM release_comments WHERE id = %d", $id)); $this->updateReleaseCommentCount($res["gid"]); } } @@ -143,19 +142,20 @@ class ReleaseComments $this->updateReleaseCommentCount($gid); return $comid; } - /** * Get release_comments rows by limit. */ public function getCommentsRange($start, $num) { - if ($start === false) - $limit = ""; - else - $limit = " LIMIT ".$start.",".$num; - - $sql = "SELECT rc.id, userid, guid, text, createddate, sourceid, CASE WHEN sourceID = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username, CASE WHEN sourceid = 0 THEN (SELECT role FROM users WHERE id = userid) ELSE '-1' END AS role, CASE WHEN sourceid =0 THEN (SELECT r.name AS rolename FROM users AS u LEFT JOIN userroles AS r ON r.id = u.role WHERE u.id = userid) ELSE (SELECT description AS rolename FROM spotnabsources WHERE id = sourceid) END AS rolename FROM release_comments rc LEFT JOIN releases r ON r.gid = rc.gid WHERE isvisible = 1 AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC ".$limit; - return $this->pdo->query($sql); + return $this->pdo->query( + sprintf(" + SELECT rc.*, r.guid + FROM release_comments rc + LEFT JOIN releases r on r.gid = rc.gid + ORDER BY rc.createddate DESC %s", + ($start === false ? '' : " LIMIT " . $num . " OFFSET " . $start) + ) + ); } /** diff --git a/resources/db/patches/0189~releases.sql b/resources/db/patches/0189~releases.sql new file mode 100644 index 000000000..f8ed41420 --- /dev/null +++ b/resources/db/patches/0189~releases.sql @@ -0,0 +1 @@ +ALTER TABLE releases ADD INDEX ix_releases_gid (gid); \ No newline at end of file diff --git a/www/admin/comments-delete.php b/www/admin/comments-delete.php index 56868fc04..8521650d0 100644 --- a/www/admin/comments-delete.php +++ b/www/admin/comments-delete.php @@ -3,12 +3,10 @@ require_once './config.php'; $page = new AdminPage(); -if (isset($_GET['id'])) -{ - $rc = new ReleaseComments(); +if (isset($_GET['id'])) { + $rc = new ReleaseComments($page->settings); $rc->deleteComment($_GET['id']); } $referrer = $_SERVER['HTTP_REFERER']; header("Location: " . $referrer); - diff --git a/www/admin/comments-list.php b/www/admin/comments-list.php index 714200c83..0b33fc9f1 100644 --- a/www/admin/comments-list.php +++ b/www/admin/comments-list.php @@ -4,16 +4,18 @@ require_once './config.php'; $page = new AdminPage(); -$releases = new ReleaseComments(); +$releases = new ReleaseComments($page->settings); $page->title = "Comments List"; $commentcount = $releases->getCommentCount(); $offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0; -$page->smarty->assign('pagertotalitems',$commentcount); -$page->smarty->assign('pageroffset',$offset); -$page->smarty->assign('pageritemsperpage',ITEMS_PER_PAGE); -$page->smarty->assign('pagerquerybase', WWW_TOP."/comments-list.php?offset="); +$page->smarty->assign([ + 'pagertotalitems' => $commentcount, + 'pageroffset' => $offset, + 'pageritemsperpage' => ITEMS_PER_PAGE, + 'pagerquerybase' => WWW_TOP."/comments-list.php?offset=", + 'pagerquerysuffix' => '']); $pager = $page->smarty->fetch("pager.tpl"); $page->smarty->assign('pager', $pager); diff --git a/www/templates_shared/views/admin/comments-list.tpl b/www/templates_shared/views/admin/comments-list.tpl index dd11d9f1d..184ef6442 100644 --- a/www/templates_shared/views/admin/comments-list.tpl +++ b/www/templates_shared/views/admin/comments-list.tpl @@ -1,38 +1,37 @@

{$page->title}

- {if $commentslist} -{$pager} - - - - - - - - - - - - - {foreach from=$commentslist item=comment} - - - - - - - - {/foreach} - - -
userdatecommenthostoptions
- {if $comment.sourceid == 0}{$comment.username}{else}{$comment.username}
(syndicated){/if} -
{$comment.createddate|date_format} ({$comment.createddate|timeago} - ago) - {$comment.text|escape:"htmlall"|nl2br}{$comment.host} - {if $comment.guid != ""}view | {/if} - delete -
+ {$pager} + + + + + + {if $comment.host}{/if} + + + {foreach from=$commentslist item=comment} + + + + {if $comment.shared == 2} + + {else} + + {/if} + {if $comment.host}{/if} + + + {/foreach} +
userdatecommenthostoptions
+ {if $comment.userid > 0} + {$comment.username} + {else} + {$comment.username} + {/if} + {$comment.createddate|timeago}{$comment.text|escape:"htmlall"|nl2br}{$comment.text|escape:"htmlall"|nl2br}{$comment.host} + {if $comment.guid}view |{/if} + delete +
{else} -

No comments available

+

No comments available

{/if}