mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-01 10:48:53 +00:00
Update comments management, add index to releases.gid for better comment load speed in admin area.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<newznab>
|
||||
<versions>
|
||||
<sql>
|
||||
<db>188</db>
|
||||
<file>188</file>
|
||||
<db>189</db>
|
||||
<file>189</file>
|
||||
</sql>
|
||||
<git>
|
||||
<tag>0.4.1</tag>
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE releases ADD INDEX ix_releases_gid (gid);
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
<h1>{$page->title}</h1>
|
||||
|
||||
{if $commentslist}
|
||||
{$pager}
|
||||
|
||||
<table style="margin-top:10px;" class="data Sortable highlight">
|
||||
|
||||
<tr>
|
||||
<th>user</th>
|
||||
<th>date</th>
|
||||
<th>comment</th>
|
||||
<th>host</th>
|
||||
<th class="mid">options</th>
|
||||
</tr>
|
||||
|
||||
|
||||
{foreach from=$commentslist item=comment}
|
||||
<tr class="{cycle values=",alt"}">
|
||||
<td>
|
||||
{if $comment.sourceid == 0}<a title="View {$comment.username}'s profile" href="{$smarty.const.WWW_TOP}/user-edit.php?id={$comment.userid}">{$comment.username}</a>{else}{$comment.username}<br/><span style="color: #ce0000;">(syndicated)</span>{/if}
|
||||
</td>
|
||||
<td width="70" title="{$comment.createddate}">{$comment.createddate|date_format} ({$comment.createddate|timeago}
|
||||
ago)
|
||||
</td>
|
||||
<td>{$comment.text|escape:"htmlall"|nl2br}</td>
|
||||
<td>{$comment.host}</td>
|
||||
<td class="mid" width="70">
|
||||
{if $comment.guid != ""}<a href="{$smarty.const.WWW_TOP}/../details/{$comment.guid}#comments">view</a> | {/if}
|
||||
<a class="confirm_action" href="{$smarty.const.WWW_TOP}/comments-delete.php?id={$comment.id}">delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
|
||||
</table>
|
||||
{$pager}
|
||||
<table style="margin-top:10px;" class="data Sortable highlight">
|
||||
<tr>
|
||||
<th>user</th>
|
||||
<th>date</th>
|
||||
<th>comment</th>
|
||||
{if $comment.host}<th>host</th>{/if}
|
||||
<th>options</th>
|
||||
</tr>
|
||||
{foreach from=$commentslist item=comment}
|
||||
<tr class="{cycle values=",alt"}">
|
||||
<td>
|
||||
{if $comment.userid > 0}
|
||||
<a href="{$smarty.const.WWW_TOP}/user-edit.php?id={$comment.userid}">{$comment.username}</a>
|
||||
{else}
|
||||
{$comment.username}
|
||||
{/if}
|
||||
</td>
|
||||
<td title="{$comment.createddate}">{$comment.createddate|timeago}</td>
|
||||
{if $comment.shared == 2}
|
||||
<td style="color:#6B2447">{$comment.text|escape:"htmlall"|nl2br}</td>
|
||||
{else}
|
||||
<td>{$comment.text|escape:"htmlall"|nl2br}</td>
|
||||
{/if}
|
||||
{if $comment.host}<td>{$comment.host}</td>{/if}
|
||||
<td>
|
||||
{if $comment.guid}<a href="{$smarty.const.WWW_TOP}/../details/{$comment.guid}#comments">view</a> |{/if}
|
||||
<a href="{$smarty.const.WWW_TOP}/comments-delete.php?id={$comment.id}">delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{else}
|
||||
<p>No comments available</p>
|
||||
<p>No comments available</p>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user