mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Add caching to some of the queries. ported from nZEDb.
This commit is contained in:
@@ -234,7 +234,7 @@ class Books
|
||||
. "GROUP BY boo.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $maxage, $exccatlist, $order[0], $order[1]
|
||||
);
|
||||
|
||||
return $this->pdo->queryDirect($sql);
|
||||
return $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
}
|
||||
|
||||
public function getBookOrder($orderby)
|
||||
|
||||
@@ -139,64 +139,75 @@ class Category
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a category is a parent.
|
||||
* Check if category is parent.
|
||||
*
|
||||
* @param $cid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isParent($cid)
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
$ret = $db->queryOneRow(sprintf("select count(*) as count from category where id = %d and parentid is null", $cid), true);
|
||||
if ($ret['count'])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
$ret = $this->pdo->query(
|
||||
sprintf("SELECT id FROM category WHERE id = %d AND parentid IS NULL", $cid),
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
return (isset($ret[0]['id']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all child categories for a parent.
|
||||
*/
|
||||
public function getChildren($cid)
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
|
||||
return $db->query(sprintf("select c.* from category c where parentid = %d", $cid), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of categories and their parents.
|
||||
* @param bool $activeonly
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFlat($activeonly = false)
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
$act = "";
|
||||
if ($activeonly)
|
||||
$act = sprintf(" where c.status = %d ", Category::STATUS_ACTIVE);
|
||||
if ($activeonly) {
|
||||
$act = sprintf(" WHERE c.status = %d ", Category::STATUS_ACTIVE);
|
||||
}
|
||||
return $this->pdo->query("SELECT c.*, (SELECT title FROM category WHERE id=c.parentid) AS parentName FROM category c " . $act . " ORDER BY c.id");
|
||||
}
|
||||
|
||||
return $db->query("select c.*, (SELECT title FROM category WHERE id=c.parentid) AS parentName from category c " . $act . " ORDER BY c.id");
|
||||
/**
|
||||
* Get children of a parent category.
|
||||
*
|
||||
* @param $cid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChildren($cid)
|
||||
{
|
||||
return $this->pdo->query(
|
||||
sprintf("SELECT c.* FROM category c WHERE parentid = %d", $cid),
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of enabled parent categories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEnabledParentNames()
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
|
||||
return $db->query("SELECT title FROM category WHERE parentid IS NULL AND status = 1");
|
||||
return $this->pdo->query(
|
||||
"SELECT title FROM category WHERE parentid IS NULL AND status = 1",
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns category id's for site disabled categories.
|
||||
* Returns category ID's for site disabled categories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDisabledIDs()
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
|
||||
return $db->query("SELECT id FROM category WHERE status = 2 OR parentid IN (SELECT id FROM category WHERE status = 2 AND parentid IS NULL)");
|
||||
return $this->pdo->query(
|
||||
"SELECT id FROM category WHERE status = 2 OR parentid IN (SELECT id FROM category WHERE status = 2 AND parentid IS NULL)",
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a category row by its id.
|
||||
*/
|
||||
@@ -251,13 +262,26 @@ class Category
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a list of categories by an array of IDs.
|
||||
* Get multiple categories.
|
||||
*
|
||||
* @param array $ids
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getByIds($ids)
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
|
||||
return $db->query(sprintf("SELECT concat(cp.title, ' > ',c.title) as title from category c inner join category cp on cp.id = c.parentid where c.id in (%s)", implode(',', $ids)));
|
||||
if (count($ids) > 0) {
|
||||
return $this->pdo->query(
|
||||
sprintf(
|
||||
"SELECT CONCAT(cp.title, ' > ',c.title) AS title
|
||||
FROM category c
|
||||
INNER JOIN category cp ON cp.id = c.parentid
|
||||
WHERE c.id IN (%s)", implode(',', $ids)
|
||||
), true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getNameByID($ID)
|
||||
@@ -280,40 +304,46 @@ class Category
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the categories in a format for use by the headermenu.tpl.
|
||||
* @param array $excludedcats
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getForMenu($excludedcats = array())
|
||||
public function getForMenu($excludedcats = [])
|
||||
{
|
||||
$db = new newznab\db\Settings();
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
|
||||
$exccatlist = "";
|
||||
if (count($excludedcats) > 0)
|
||||
$exccatlist = " and id not in (" . implode(",", $excludedcats) . ")";
|
||||
$exccatlist = '';
|
||||
if (count($excludedcats) > 0) {
|
||||
$exccatlist = ' AND id NOT IN (' . implode(',', $excludedcats) . ')';
|
||||
}
|
||||
|
||||
$arr = $db->query(sprintf("select * from category where status = %d %s", Category::STATUS_ACTIVE, $exccatlist), true);
|
||||
foreach ($arr as $a)
|
||||
if ($a["parentid"] == "")
|
||||
$arr = $this->pdo->query(
|
||||
sprintf('SELECT * FROM category WHERE status = %d %s', Category::STATUS_ACTIVE, $exccatlist),
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
foreach ($arr as $a) {
|
||||
if ($a['parentid'] == '') {
|
||||
$ret[] = $a;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($ret as $key => $parent) {
|
||||
$subcatlist = array();
|
||||
$subcatnames = array();
|
||||
$subcatlist = [];
|
||||
$subcatnames = [];
|
||||
foreach ($arr as $a) {
|
||||
if ($a["parentid"] == $parent["id"]) {
|
||||
if ($a['parentid'] == $parent['id']) {
|
||||
$subcatlist[] = $a;
|
||||
$subcatnames[] = $a["title"];
|
||||
$subcatnames[] = $a['title'];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($subcatlist) > 0) {
|
||||
array_multisort($subcatnames, SORT_ASC, $subcatlist);
|
||||
$ret[$key]["subcatlist"] = $subcatlist;
|
||||
$ret[$key]['subcatlist'] = $subcatlist;
|
||||
} else {
|
||||
unset($ret[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ class Film
|
||||
implode(',', $imdbIDs)
|
||||
)
|
||||
)
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ class Film
|
||||
$order[1],
|
||||
($start === false ? '' : ' LIMIT ' . $num . ' OFFSET ' . $start)
|
||||
);
|
||||
return $this->pdo->queryDirect($sql);
|
||||
return $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -241,7 +241,7 @@ class Games
|
||||
$exccatlist,
|
||||
$order[0],
|
||||
$order[1]
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Genres
|
||||
|
||||
public function getGenres($type = '', $activeonly = false)
|
||||
{
|
||||
return $this->pdo->query($this->getListQuery($type, $activeonly));
|
||||
return $this->pdo->query($this->getListQuery($type, $activeonly), true,NN_CACHE_EXPIRY_LONG);
|
||||
}
|
||||
|
||||
private function getListQuery($type = '', $activeonly = false)
|
||||
@@ -126,6 +126,6 @@ class Genres
|
||||
|
||||
public function getDisabledIDs()
|
||||
{
|
||||
return $this->pdo->query("SELECT id FROM genres WHERE disabled = 1");
|
||||
return $this->pdo->query("SELECT id FROM genres WHERE disabled = 1", true, NN_CACHE_EXPIRY_LONG);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,8 @@ class Groups
|
||||
LEFT OUTER JOIN
|
||||
(SELECT groupid, COUNT(id) AS num FROM releases GROUP BY groupid) rel
|
||||
ON rel.groupid = groups.id
|
||||
ORDER BY groups.name"
|
||||
ORDER BY groups.name",
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,7 +50,9 @@ class Groups
|
||||
public function getGroupsForSelect()
|
||||
{
|
||||
|
||||
$categories = $this->pdo->query("SELECT * FROM groups WHERE active = 1 ORDER BY name");
|
||||
$categories = $this->pdo->query("SELECT * FROM groups WHERE active = 1 ORDER BY name",
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
$temp_array = array();
|
||||
|
||||
$temp_array[-1] = "--Please Select--";
|
||||
@@ -76,7 +79,9 @@ class Groups
|
||||
public function getActive()
|
||||
{
|
||||
|
||||
return $this->pdo->query("SELECT * FROM groups WHERE active = 1 ORDER BY name");
|
||||
return $this->pdo->query("SELECT * FROM groups WHERE active = 1 ORDER BY name",
|
||||
true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,31 +142,37 @@ class Groups
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups rows for browse list by limit.
|
||||
* @param $start
|
||||
* @param $num
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRange($start, $num, $groupname = "", $activeonly = false)
|
||||
public function getRange($start, $num, $groupname = "")
|
||||
{
|
||||
|
||||
if ($start === false)
|
||||
$limit = "";
|
||||
else
|
||||
$limit = " LIMIT " . $start . "," . $num;
|
||||
|
||||
$grpsql = '';
|
||||
if ($groupname != "")
|
||||
$grpsql .= sprintf("and groups.name like %s ", $this->pdo->escapeString("%" . $groupname . "%"));
|
||||
if ($activeonly == true)
|
||||
$grpsql .= "and active=1 ";
|
||||
|
||||
$sql = sprintf("SELECT groups.*, COALESCE(rel.num, 0) AS num_releases
|
||||
FROM groups
|
||||
LEFT OUTER JOIN
|
||||
(
|
||||
SELECT groupid, COUNT(id) AS num FROM releases group by groupid
|
||||
) rel ON rel.groupid = groups.id WHERE 1=1 %s ORDER BY groups.name " . $limit, $grpsql
|
||||
return $this->pdo->query(
|
||||
sprintf("
|
||||
SELECT groups.*,
|
||||
COALESCE(rel.num, 0) AS num_releases
|
||||
FROM groups
|
||||
LEFT OUTER JOIN
|
||||
(SELECT groupid, COUNT(id) AS num
|
||||
FROM releases GROUP BY groupid
|
||||
) rel
|
||||
ON rel.groupid = groups.id
|
||||
WHERE 1 = 1 %s
|
||||
ORDER BY groups.name " .
|
||||
($start === false ? '' : " LIMIT " . $num . " OFFSET " . $start),
|
||||
($groupname !== ''
|
||||
?
|
||||
sprintf(
|
||||
"AND groups.name LIKE %s ",
|
||||
$this->pdo->escapeString("%" . $groupname . "%")
|
||||
)
|
||||
: ''
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
|
||||
return $this->pdo->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,7 +408,9 @@ class Groups
|
||||
*/
|
||||
public function getActiveBackfill()
|
||||
{
|
||||
return $this->pdo->query("SELECT * FROM groups WHERE backfill = 1 AND last_record != 0 ORDER BY name");
|
||||
return $this->pdo->query("SELECT * FROM groups WHERE backfill = 1 AND last_record != 0 ORDER BY name",
|
||||
true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,7 +418,9 @@ class Groups
|
||||
*/
|
||||
public function getActiveByDateBackfill()
|
||||
{
|
||||
return $this->pdo->query("SELECT * FROM groups WHERE backfill = 1 AND last_record != 0 ORDER BY first_record_postdate DESC");
|
||||
return $this->pdo->query("SELECT * FROM groups WHERE backfill = 1 AND last_record != 0 ORDER BY first_record_postdate DESC",
|
||||
true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +479,9 @@ class Groups
|
||||
*/
|
||||
public function getActiveIDs()
|
||||
{
|
||||
return $this->pdo->query("SELECT id FROM groups WHERE active = 1 ORDER BY name");
|
||||
return $this->pdo->query("SELECT id FROM groups WHERE active = 1 ORDER BY name",
|
||||
true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -592,7 +609,7 @@ class Groups
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRangeActive($start, $num, $groupname="")
|
||||
public function getRangeActive($start, $num, $groupname = "")
|
||||
{
|
||||
return $this->pdo->query(
|
||||
sprintf("
|
||||
@@ -606,16 +623,17 @@ class Groups
|
||||
ON rel.groupid = groups.id
|
||||
WHERE 1 = 1 %s
|
||||
AND active = 1
|
||||
ORDER BY groups.name " . ($start === false ? '' : " LIMIT " . $num . " OFFSET " .$start),
|
||||
ORDER BY groups.name " .
|
||||
($start === false ? '' : " LIMIT " . $num . " OFFSET " . $start),
|
||||
($groupname !== ''
|
||||
?
|
||||
sprintf(
|
||||
"AND groups.name LIKE %s ",
|
||||
$this->pdo->escapeString("%".$groupname."%")
|
||||
$this->pdo->escapeString("%" . $groupname . "%")
|
||||
)
|
||||
: ''
|
||||
)
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
}
|
||||
|
||||
@@ -626,7 +644,7 @@ class Groups
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRangeInactive($start, $num, $groupname="")
|
||||
public function getRangeInactive($start, $num, $groupname = "")
|
||||
{
|
||||
return $this->pdo->query(
|
||||
sprintf("
|
||||
@@ -640,15 +658,16 @@ class Groups
|
||||
ON rel.groupid = groups.id
|
||||
WHERE 1 = 1 %s
|
||||
AND active = 0
|
||||
ORDER BY groups.name " . ($start === false ? '' : " LIMIT ".$num." OFFSET ".$start),
|
||||
ORDER BY groups.name " .
|
||||
($start === false ? '' : " LIMIT " . $num . " OFFSET " . $start),
|
||||
($groupname !== ''
|
||||
? sprintf(
|
||||
"AND groups.name LIKE %s ",
|
||||
$this->pdo->escapeString("%".$groupname."%")
|
||||
$this->pdo->escapeString("%" . $groupname . "%")
|
||||
)
|
||||
: ''
|
||||
)
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_SHORT
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ class Konsole
|
||||
. "r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s
|
||||
%s "
|
||||
. "GROUP BY con.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $exccatlist, $order[0], $order[1]
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,8 @@ class Musik
|
||||
}
|
||||
|
||||
$order = $this->getMusicOrder($orderby);
|
||||
return $this->pdo->query(sprintf("SELECT GROUP_CONCAT(r.id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_id, "
|
||||
return $this->pdo->query(
|
||||
sprintf("SELECT GROUP_CONCAT(r.id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_id, "
|
||||
. "GROUP_CONCAT(r.rarinnerfilecount ORDER BY r.postdate DESC SEPARATOR ',') as grp_rarinnerfilecount, "
|
||||
. "GROUP_CONCAT(r.haspreview ORDER BY r.postdate DESC SEPARATOR ',') AS grp_haspreview, "
|
||||
. "GROUP_CONCAT(r.passwordstatus ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_password, "
|
||||
@@ -252,7 +253,9 @@ class Musik
|
||||
. "INNER JOIN musicinfo m ON m.id = r.musicinfoid "
|
||||
. "WHERE r.nzbstatus = 1 AND m.title != '' AND "
|
||||
. "r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s %s "
|
||||
. "GROUP BY m.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $exccatlist, $order[0], $order[1]));
|
||||
. "GROUP BY m.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $exccatlist, $order[0], $order[1]),
|
||||
true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,7 +118,7 @@ class Releases
|
||||
INNER JOIN groups g ON g.id = r.groupid
|
||||
WHERE r.nzbstatus = %d',
|
||||
NZB::NZB_ADDED
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class Releases
|
||||
ORDER BY r.postdate DESC %s",
|
||||
NZB::NZB_ADDED,
|
||||
($start === false ? '' : 'LIMIT ' . $num . ' OFFSET ' . $start)
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -221,8 +221,7 @@ class Releases
|
||||
$orderBy[0],
|
||||
$orderBy[1],
|
||||
($start === false ? '' : ' LIMIT ' . $num . ' OFFSET ' . $start)
|
||||
),
|
||||
true, NN_CACHE_EXPIRY_MEDIUM
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -242,12 +241,14 @@ class Releases
|
||||
if (!is_null($this->passwordSettingBuffer)) {
|
||||
return $this->passwordSettingBuffer;
|
||||
}
|
||||
$setting = $this->pdo->queryOneRow(
|
||||
"SELECT value FROM settings WHERE setting = 'showpasswordedrelease'"
|
||||
);
|
||||
|
||||
$passwordStatus = ('= ' . Releases::PASSWD_NONE);
|
||||
if ($setting !== false) {
|
||||
switch ($setting['value']) {
|
||||
$setting = $this->pdo->query(
|
||||
"SELECT value FROM settings WHERE setting = 'showpasswordedrelease'",
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
if (isset($setting[0]['value']) && is_numeric($setting[0]['value'])) {
|
||||
switch ($setting[0]['value']) {
|
||||
case 1:
|
||||
$passwordStatus = ('<= ' . Releases::PASSWD_POTENTIAL);
|
||||
break;
|
||||
@@ -423,6 +424,31 @@ class Releases
|
||||
return $temp_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache of concatenated category ID's used in queries.
|
||||
* @var null|array
|
||||
*/
|
||||
private $concatenatedCategoryIDsCache = null;
|
||||
|
||||
/**
|
||||
* Gets / sets a string of concatenated category ID's used in queries.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getConcatenatedCategoryIDs()
|
||||
{
|
||||
if (is_null($this->concatenatedCategoryIDsCache)) {
|
||||
$result = $this->pdo->query(
|
||||
"SELECT CONCAT(cp.id, ',', c.id) AS category_ids FROM category c INNER JOIN category cp ON cp.id = c.parentid",
|
||||
true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
if (isset($result[0]['category_ids'])) {
|
||||
$this->concatenatedCategoryIDsCache = $result[0]['category_ids'];
|
||||
}
|
||||
}
|
||||
return $this->concatenatedCategoryIDsCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get releases for RSS.
|
||||
*
|
||||
@@ -443,28 +469,9 @@ class Releases
|
||||
|
||||
if (count($cat)) {
|
||||
if ($cat[0] == -2) {
|
||||
$cartSearch = sprintf(' INNER JOIN usercart ON usercart.userid = %d AND usercart.releaseid = r.id ', $userID);
|
||||
$cartSearch = sprintf(' INNER JOIN users_releases ON users_releases.user_id = %d AND users_releases.releaseid = r.id ', $userID);
|
||||
} else if ($cat[0] != -1) {
|
||||
$catSearch = ' AND (';
|
||||
$Category = new Category(['Settings' => $this->pdo]);
|
||||
foreach ($cat as $category) {
|
||||
if ($category != -1) {
|
||||
if ($Category->isParent($category)) {
|
||||
$children = $Category->getChildren($category);
|
||||
$childList = '-99';
|
||||
foreach ($children as $child) {
|
||||
$childList .= ', ' . $child['id'];
|
||||
}
|
||||
|
||||
if ($childList != '-99') {
|
||||
$catSearch .= ' r.categoryid IN (' . $childList . ') OR ';
|
||||
}
|
||||
} else {
|
||||
$catSearch .= sprintf(' r.categoryid = %d OR ', $category);
|
||||
}
|
||||
}
|
||||
}
|
||||
$catSearch .= '1=2 )';
|
||||
$catSearch = $this->categorySQL($cat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +480,7 @@ class Releases
|
||||
"SELECT r.*, m.cover, m.imdbid, m.rating, m.plot,
|
||||
m.year, m.genre, m.director, m.actors, g.name AS group_name,
|
||||
CONCAT(cp.title, ' > ', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
COALESCE(cp.id,0) AS parentCategoryid,
|
||||
mu.title AS mu_title, mu.url AS mu_url, mu.artist AS mu_artist,
|
||||
mu.publisher AS mu_publisher, mu.releasedate AS mu_releasedate,
|
||||
@@ -487,13 +494,14 @@ class Releases
|
||||
INNER JOIN groups g ON g.id = r.groupid
|
||||
LEFT OUTER JOIN movieinfo m ON m.imdbid = r.imdbid AND m.title != ''
|
||||
LEFT OUTER JOIN musicinfo mu ON mu.id = r.musicinfoid
|
||||
LEFT OUTER JOIN genres mug ON mug.id = mu.genreid
|
||||
LEFT OUTER JOIN genres mug ON mug.id = mu.genre_id
|
||||
LEFT OUTER JOIN consoleinfo co ON co.id = r.consoleinfoid
|
||||
LEFT OUTER JOIN genres cog ON cog.id = co.genreid %s
|
||||
LEFT OUTER JOIN genres cog ON cog.id = co.genre_id %s
|
||||
WHERE r.passwordstatus %s
|
||||
AND r.nzbstatus = %d
|
||||
%s %s %s %s
|
||||
ORDER BY postdate DESC %s",
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$cartSearch,
|
||||
$this->showPasswords(),
|
||||
NZB::NZB_ADDED,
|
||||
@@ -502,7 +510,7 @@ class Releases
|
||||
($aniDbID > -1 ? sprintf(' AND r.anidbid = %d %s ', $aniDbID, ($catSearch == '' ? $catLimit : '')) : ''),
|
||||
($airDate > -1 ? sprintf(' AND r.tvairdate >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ', $airDate) : ''),
|
||||
(' LIMIT 0,' . ($offset > 100 ? 100 : $offset))
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -522,7 +530,7 @@ class Releases
|
||||
sprintf("
|
||||
SELECT r.*, tvr.rageid, tvr.releasetitle, g.name AS group_name,
|
||||
CONCAT(cp.title, '-', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
COALESCE(cp.id,0) AS parentCategoryid
|
||||
FROM releases r
|
||||
INNER JOIN category c ON c.id = r.categoryid
|
||||
@@ -534,13 +542,14 @@ class Releases
|
||||
AND r.categoryid BETWEEN 5000 AND 5999
|
||||
AND r.passwordstatus %s
|
||||
ORDER BY postdate DESC %s",
|
||||
$this->uSQL($this->pdo->query(sprintf('SELECT rageid, categoryid FROM userseries WHERE userid = %d', $userID), true), 'rageid'),
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$this->uSQL($this->pdo->query(sprintf('SELECT rageid, categoryid FROM user_series WHERE user_id = %d', $userID), true), 'rageid'),
|
||||
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
|
||||
($airDate > -1 ? sprintf(' AND r.tvairdate >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ', $airDate) : ''),
|
||||
NZB::NZB_ADDED,
|
||||
$this->showPasswords(),
|
||||
(' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0')
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -559,7 +568,7 @@ class Releases
|
||||
sprintf("
|
||||
SELECT r.*, mi.title AS releasetitle, g.name AS group_name,
|
||||
CONCAT(cp.title, '-', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
COALESCE(cp.id,0) AS parentCategoryid
|
||||
FROM releases r
|
||||
INNER JOIN category c ON c.id = r.categoryid
|
||||
@@ -571,12 +580,13 @@ class Releases
|
||||
AND r.categoryid BETWEEN 2000 AND 2999
|
||||
AND r.passwordstatus %s
|
||||
ORDER BY postdate DESC %s",
|
||||
$this->uSQL($this->pdo->query(sprintf('SELECT imdbid, categoryid FROM usermovies WHERE userid = %d', $userID), true), 'imdbid'),
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$this->uSQL($this->pdo->query(sprintf('SELECT imdbid, categoryid FROM user_movies WHERE user_id = %d', $userID), true), 'imdbid'),
|
||||
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
|
||||
NZB::NZB_ADDED,
|
||||
$this->showPasswords(),
|
||||
(' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0')
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -597,11 +607,13 @@ class Releases
|
||||
$orderBy = $this->getBrowseOrder($orderBy);
|
||||
return $this->pdo->query(
|
||||
sprintf(
|
||||
"SELECT r.*, CONCAT(cp.title, '-', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids, groups.name AS group_name,
|
||||
"SELECT r.*,
|
||||
CONCAT(cp.title, '-', c.title) AS category_name,
|
||||
%s AS category_ids,
|
||||
groups.name AS group_name,
|
||||
rn.id AS nfoid, re.releaseid AS reid
|
||||
FROM releases r
|
||||
LEFT OUTER JOIN releasevideo re ON re.releaseid = r.id
|
||||
LEFT OUTER JOIN video_data re ON re.releaseid = r.id
|
||||
INNER JOIN groups ON groups.id = r.groupid
|
||||
LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.nfo IS NOT NULL
|
||||
INNER JOIN category c ON c.id = r.categoryid
|
||||
@@ -612,6 +624,7 @@ class Releases
|
||||
AND r.passwordstatus %s
|
||||
%s
|
||||
ORDER BY %s %s %s",
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$this->uSQL($userShows, 'rageid'),
|
||||
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
|
||||
NZB::NZB_ADDED,
|
||||
@@ -620,7 +633,7 @@ class Releases
|
||||
$orderBy[0],
|
||||
$orderBy[1],
|
||||
($offset === false ? '' : (' LIMIT ' . $limit . ' OFFSET ' . $offset))
|
||||
)
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -719,12 +732,12 @@ class Releases
|
||||
DELETE r, rn, rc, uc, rf, ra, rs, rv, re
|
||||
FROM releases r
|
||||
LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id
|
||||
LEFT OUTER JOIN releasecomment rc ON rc.releaseid = r.id
|
||||
LEFT OUTER JOIN usercart uc ON uc.releaseid = r.id
|
||||
LEFT OUTER JOIN releasefiles rf ON rf.releaseid = r.id
|
||||
LEFT OUTER JOIN releaseaudio ra ON ra.releaseid = r.id
|
||||
LEFT OUTER JOIN releasesubs rs ON rs.releaseid = r.id
|
||||
LEFT OUTER JOIN releasevideo rv ON rv.releaseid = r.id
|
||||
LEFT OUTER JOIN release_comments rc ON rc.releaseid = r.id
|
||||
LEFT OUTER JOIN users_releases uc ON uc.releaseid = r.id
|
||||
LEFT OUTER JOIN release_files rf ON rf.releaseid = r.id
|
||||
LEFT OUTER JOIN audio_data ra ON ra.releaseid = r.id
|
||||
LEFT OUTER JOIN release_subtitles rs ON rs.releaseid = r.id
|
||||
LEFT OUTER JOIN video_data rv ON rv.releaseid = r.id
|
||||
LEFT OUTER JOIN releaseextrafull re ON re.releaseid = r.id
|
||||
WHERE r.guid = %s',
|
||||
$this->pdo->escapeString($identifiers['g'])
|
||||
@@ -996,18 +1009,19 @@ class Releases
|
||||
$baseSql = sprintf(
|
||||
"SELECT r.*,
|
||||
CONCAT(cp.title, ' > ', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
groups.name AS group_name,
|
||||
rn.id AS nfoid,
|
||||
re.releaseid AS reid,
|
||||
cp.id AS categoryparentid
|
||||
FROM releases r
|
||||
LEFT OUTER JOIN releasevideo re ON re.releaseid = r.id
|
||||
LEFT OUTER JOIN video_data re ON re.releaseid = r.id
|
||||
LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id
|
||||
INNER JOIN groups ON groups.id = r.groupid
|
||||
INNER JOIN category c ON c.id = r.categoryid
|
||||
INNER JOIN category cp ON cp.id = c.parentid
|
||||
%s",
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$whereSql
|
||||
);
|
||||
|
||||
@@ -1023,7 +1037,7 @@ class Releases
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
$releases = $this->pdo->query($sql);
|
||||
$releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
if ($releases && count($releases)) {
|
||||
$releases[0]['_totalrows'] = $this->getPagerCount($baseSql);
|
||||
}
|
||||
@@ -1063,17 +1077,18 @@ class Releases
|
||||
$baseSql = sprintf(
|
||||
"SELECT r.*,
|
||||
concat(cp.title, ' > ', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
groups.name AS group_name,
|
||||
rn.id AS nfoid,
|
||||
re.releaseid AS reid
|
||||
FROM releases r
|
||||
INNER JOIN category c ON c.id = r.categoryid
|
||||
INNER JOIN groups ON groups.id = r.groupid
|
||||
LEFT OUTER JOIN releasevideo re ON re.releaseid = r.id
|
||||
LEFT OUTER JOIN video_data re ON re.releaseid = r.id
|
||||
LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.nfo IS NOT NULL
|
||||
INNER JOIN category cp ON cp.id = c.parentid
|
||||
%s",
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$whereSql
|
||||
);
|
||||
|
||||
@@ -1085,7 +1100,7 @@ class Releases
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
$releases = $this->pdo->query($sql);
|
||||
$releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
if ($releases && count($releases)) {
|
||||
$releases[0]['_totalrows'] = $this->getPagerCount($baseSql);
|
||||
}
|
||||
@@ -1121,7 +1136,7 @@ class Releases
|
||||
$baseSql = sprintf(
|
||||
"SELECT r.*,
|
||||
CONCAT(cp.title, ' > ', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
groups.name AS group_name,
|
||||
rn.id AS nfoid
|
||||
FROM releases r
|
||||
@@ -1130,6 +1145,7 @@ class Releases
|
||||
LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.nfo IS NOT NULL
|
||||
INNER JOIN category cp ON cp.id = c.parentid
|
||||
%s",
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$whereSql
|
||||
);
|
||||
|
||||
@@ -1141,7 +1157,7 @@ class Releases
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
$releases = $this->pdo->query($sql);
|
||||
$releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
if ($releases && count($releases)) {
|
||||
$releases[0]['_totalrows'] = $this->getPagerCount($baseSql);
|
||||
}
|
||||
@@ -1178,7 +1194,7 @@ class Releases
|
||||
$baseSql = sprintf(
|
||||
"SELECT r.*,
|
||||
concat(cp.title, ' > ', c.title) AS category_name,
|
||||
CONCAT(cp.id, ',', c.id) AS category_ids,
|
||||
%s AS category_ids,
|
||||
g.name AS group_name,
|
||||
rn.id AS nfoid
|
||||
FROM releases r
|
||||
@@ -1187,6 +1203,7 @@ class Releases
|
||||
LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.nfo IS NOT NULL
|
||||
INNER JOIN category cp ON cp.id = c.parentid
|
||||
%s",
|
||||
$this->getConcatenatedCategoryIDs(),
|
||||
$whereSql
|
||||
);
|
||||
|
||||
@@ -1198,7 +1215,7 @@ class Releases
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
$releases = $this->pdo->query($sql);
|
||||
$releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
if ($releases && count($releases)) {
|
||||
$releases[0]['_totalrows'] = $this->getPagerCount($baseSql);
|
||||
}
|
||||
@@ -1465,7 +1482,7 @@ class Releases
|
||||
GROUP BY id, searchname, adddate
|
||||
HAVING SUM(grabs) > 0
|
||||
ORDER BY grabs DESC
|
||||
LIMIT 10'
|
||||
LIMIT 10', true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1481,7 +1498,7 @@ class Releases
|
||||
GROUP BY id, searchname, adddate
|
||||
HAVING SUM(comments) > 0
|
||||
ORDER BY comments DESC
|
||||
LIMIT 10'
|
||||
LIMIT 10', true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1494,7 +1511,7 @@ class Releases
|
||||
INNER JOIN releases r ON r.categoryid = category.id
|
||||
WHERE r.adddate > NOW() - INTERVAL 1 WEEK
|
||||
GROUP BY concat(cp.title, ' > ', category.title)
|
||||
ORDER BY COUNT(*) DESC"
|
||||
ORDER BY COUNT(*) DESC", true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1505,7 +1522,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestMovies()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.imdbid, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
postdate, categoryid, comments, grabs,
|
||||
m.cover
|
||||
@@ -1516,7 +1533,7 @@ class Releases
|
||||
AND m.cover = 1
|
||||
AND r.id in (select max(id) from releases where imdbid > 0 group by imdbid)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 24"
|
||||
LIMIT 24", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1527,7 +1544,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestXXX()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.xxxinfo_id, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
r.postdate, r.categoryid, r.comments, r.grabs,
|
||||
xxx.cover, xxx.title
|
||||
@@ -1538,7 +1555,7 @@ class Releases
|
||||
AND xxx.cover = 1
|
||||
AND r.id in (select max(id) from releases where xxxinfo_id > 0 group by xxxinfo_id)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 24"
|
||||
LIMIT 24", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1549,7 +1566,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestConsole()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.consoleinfoid, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
r.postdate, r.categoryid, r.comments, r.grabs,
|
||||
con.cover
|
||||
@@ -1560,7 +1577,7 @@ class Releases
|
||||
AND con.cover > 0
|
||||
AND r.id in (select max(id) from releases where consoleinfoid > 0 group by consoleinfoid)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 35"
|
||||
LIMIT 35", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1571,7 +1588,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestGames()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.gamesinfo_id, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
r.postdate, r.categoryid, r.comments, r.grabs,
|
||||
gi.cover
|
||||
@@ -1582,7 +1599,7 @@ class Releases
|
||||
AND gi.cover > 0
|
||||
AND r.id in (select max(id) from releases where gamesinfo_id > 0 group by gamesinfo_id)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 35"
|
||||
LIMIT 35", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1593,7 +1610,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestMP3s()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.musicinfoid, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
r.postdate, r.categoryid, r.comments, r.grabs,
|
||||
m.cover
|
||||
@@ -1605,7 +1622,7 @@ class Releases
|
||||
AND m.cover > 0
|
||||
AND r.id in (select max(id) from releases where musicinfoid > 0 group by musicinfoid)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 24"
|
||||
LIMIT 24", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1616,7 +1633,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestBooks()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.bookinfoid, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
r.postdate, r.categoryid, r.comments, r.grabs,
|
||||
b.url, b.cover, b.title as booktitle, b.author
|
||||
@@ -1628,7 +1645,7 @@ class Releases
|
||||
AND b.cover > 0
|
||||
AND r.id in (select max(id) from releases where bookinfoid > 0 group by bookinfoid)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 24"
|
||||
LIMIT 24", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1639,7 +1656,7 @@ class Releases
|
||||
*/
|
||||
public function getNewestTV()
|
||||
{
|
||||
return $this->pdo->queryDirect(
|
||||
return $this->pdo->query(
|
||||
"SELECT r.rageid, r.guid, r.name, r.searchname, r.size, r.completion,
|
||||
r.postdate, r.categoryid, r.comments, r.grabs,
|
||||
tv.id as tvid, tv.imgdata, tv.releasetitle as tvtitle
|
||||
@@ -1650,7 +1667,7 @@ class Releases
|
||||
AND length(tv.imgdata) > 0
|
||||
AND r.id in (select max(id) from releases where rageid > 0 group by rageid)
|
||||
ORDER BY r.postdate DESC
|
||||
LIMIT 24"
|
||||
LIMIT 24", true, NN_CACHE_EXPIRY_LONG
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user