mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 17:28:55 +00:00
Fix the caching, add maximum header support.
This commit is contained in:
@@ -6,22 +6,26 @@ use newznab\db\Settings;
|
||||
|
||||
$pdo = new Settings();
|
||||
|
||||
$maxHeaders = $pdo->getSetting('max.headers.iteration') ?: 1000000;
|
||||
|
||||
// Create the connection here and pass
|
||||
$nntp = new \NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect() !== true) {
|
||||
exit($pdo->log->error("Unable to connect to usenet."));
|
||||
}
|
||||
$binaries = new \Binaries(['NNTP' => $nntp, 'Settings' => $pdo]);
|
||||
$binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo]);
|
||||
|
||||
if (isset($argv[1]) && !is_numeric($argv[1])) {
|
||||
$groupName = $argv[1];
|
||||
echo $pdo->log->header("Updating group: $groupName");
|
||||
|
||||
$grp = new \Groups(['Settings' => $pdo]);
|
||||
$grp = new Groups(['Settings' => $pdo]);
|
||||
$group = $grp->getByName($groupName);
|
||||
if (is_array($group)) {
|
||||
$binaries->updateGroup($group, (isset($argv[2]) && is_numeric($argv[2]) && $argv[2] > 0 ? $argv[2] : 0));
|
||||
$binaries->updateGroup($group,
|
||||
(isset($argv[2]) && is_numeric($argv[2]) && $argv[2] > 0 ? $argv[2] : $maxHeaders));
|
||||
}
|
||||
} else {
|
||||
$binaries->updateAllGroups((isset($argv[1]) && is_numeric($argv[1]) && $argv[1] > 0 ? $argv[1] : 0));
|
||||
$binaries->updateAllGroups((isset($argv[1]) && is_numeric($argv[1]) && $argv[1] > 0 ? $argv[1] :
|
||||
$maxHeaders));
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
<newznab>
|
||||
<versions>
|
||||
<sql>
|
||||
<db>157</db>
|
||||
<file>157</file>
|
||||
<db>158</db>
|
||||
<file>158</file>
|
||||
</sql>
|
||||
<git>
|
||||
<tag>0.4.1</tag>
|
||||
|
||||
@@ -460,7 +460,7 @@ class Tmux
|
||||
public function stopIfRunning()
|
||||
{
|
||||
if ($this->isRunning() == 1) {
|
||||
$this->pdo->queryExec("UPDATE tmux SET value = '0' WHERE setting = 'RUNNING'");
|
||||
$this->pdo->queryExec("UPDATE tmux SET value = '0' WHERE setting = 'running'");
|
||||
$sleep = $this->get()->monitor_delay;
|
||||
echo $this->pdo->log->header("Stopping tmux scripts and waiting $sleep seconds for all panes to shutdown");
|
||||
sleep($sleep);
|
||||
@@ -472,7 +472,7 @@ class Tmux
|
||||
public function startRunning()
|
||||
{
|
||||
if (!$this->isRunning()) {
|
||||
return $this->pdo->queryExec("UPDATE tmux SET value = '1' WHERE setting = 'RUNNING'");
|
||||
return $this->pdo->queryExec("UPDATE tmux SET value = '1' WHERE setting = 'running'");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,12 +36,6 @@ class Cache
|
||||
*/
|
||||
private $socketFile;
|
||||
|
||||
/**
|
||||
* Does the user have igBinary support and wants to use it?
|
||||
* @var bool
|
||||
*/
|
||||
private $IgBinarySupport = false;
|
||||
|
||||
/**
|
||||
* Store data on the cache server.
|
||||
*
|
||||
@@ -55,7 +49,6 @@ class Cache
|
||||
public function set($key, $data, $expiration)
|
||||
{
|
||||
if ($this->ping()) {
|
||||
$this->serializeData($data);
|
||||
switch (NN_CACHE_TYPE) {
|
||||
case self::TYPE_REDIS:
|
||||
case self::TYPE_MEMCACHED:
|
||||
@@ -67,30 +60,6 @@ class Cache
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize data, or not based on admin setting.
|
||||
*
|
||||
* @param string|array $data
|
||||
*/
|
||||
private function serializeData(&$data)
|
||||
{
|
||||
switch (NN_CACHE_SERIALIZER) {
|
||||
case self::SERIALIZER_IGBINARY:
|
||||
if ($this->IgBinarySupport) {
|
||||
$data = igbinary_serialize($data);
|
||||
} else {
|
||||
$data = serialize($data);
|
||||
}
|
||||
break;
|
||||
case self::SERIALIZER_PHP:
|
||||
$data = serialize($data);
|
||||
break;
|
||||
case self::SERIALIZER_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to retrieve a value from the cache server, if not set it.
|
||||
*
|
||||
@@ -112,36 +81,11 @@ class Cache
|
||||
$data = apc_fetch($key);
|
||||
break;
|
||||
}
|
||||
$this->unserializeData($data);
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-serialize data, or not based on admin setting.
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
private function unserializeData(&$data)
|
||||
{
|
||||
switch (NN_CACHE_SERIALIZER) {
|
||||
case self::SERIALIZER_IGBINARY:
|
||||
if ($this->IgBinarySupport) {
|
||||
$data = igbinary_unserialize($data);
|
||||
} else {
|
||||
$data = unserialize($data);
|
||||
}
|
||||
break;
|
||||
case self::SERIALIZER_PHP:
|
||||
$data = unserialize($data);
|
||||
break;
|
||||
case self::SERIALIZER_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete data tied to a key on the cache server.
|
||||
*
|
||||
@@ -272,8 +216,9 @@ class Cache
|
||||
break;
|
||||
|
||||
case self::TYPE_APC:
|
||||
if (!function_exists('apc_set')) {
|
||||
throw new CacheException('The APC extension is not loaded!');
|
||||
// Faster than checking if apcu or apc is loaded.
|
||||
if (!function_exists('apc_add')) {
|
||||
throw new CacheException('The APCu extension is not loaded or enabled!');
|
||||
}
|
||||
$this->connect();
|
||||
break;
|
||||
@@ -395,14 +340,17 @@ class Cache
|
||||
|
||||
switch (NN_CACHE_TYPE) {
|
||||
case self::TYPE_REDIS:
|
||||
// No way to check since phpredis has no constants or functions for this.
|
||||
// If this is not defined, it means phpredis was not compiled with --enable-redis-igbinary
|
||||
if (!defined('\Redis::SERIALIZER_IGBINARY')) {
|
||||
throw new CacheException('Error: phpredis was not compiled with igbinary support!');
|
||||
}
|
||||
return \Redis::SERIALIZER_IGBINARY;
|
||||
case self::TYPE_MEMCACHED:
|
||||
if (\Memcached::HAVE_IGBINARY > 0) {
|
||||
return \Memcached::SERIALIZER_IGBINARY;
|
||||
}
|
||||
throw new CacheException('Error: You have not compiled Memcached with igbinary support!');
|
||||
case self::TYPE_APC: // No way to check, since apc.serializer can not be fetched using ini_get.
|
||||
case self::TYPE_APC: // Ignore - set by apc.serializer setting.
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
INSERT IGNORE INTO settings (section, subsection, name, value, hint, setting)
|
||||
VALUES (
|
||||
'max',
|
||||
'headers',
|
||||
'iteration',
|
||||
1000000,
|
||||
'The maximum number of headers that update binaries sees as the total range. This ensure that a total of no more than this is attempted to be downloaded at one time per group.',
|
||||
'max.headers.iteration'
|
||||
);
|
||||
Reference in New Issue
Block a user