<?php require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'indexer.php'); use nzedb\db\Settings; $pdo = new Settings(); if (isset($argv[1]) && in_array($argv[1], ['space', 'analyze', 'full'])) { if ($argv[1] === 'analyze') { echo $pdo->log->header('Analyzing MySQL tables, this can take a while...' . PHP_EOL); } else { echo $pdo->log->header('Optimizing MySQL tables, should be quick...' . PHP_EOL); } $tableCount = $pdo->optimise(false, $argv[1], isset($argv[2]) && $argv[2] === 'true', isset($argv[3]) ? [$argv[3]] : []); if ($tableCount > 0 && $argv[1] === 'analyze') { exit($pdo->log->header("Analyzed {$tableCount} MySQL tables successfully." . PHP_EOL)); } else { if ($tableCount > 0) { exit($pdo->log->header("Optimized {$tableCount} MySQL tables successfully." . PHP_EOL)); } else { exit($pdo->log->notice('No MySQL tables to optimize.' . PHP_EOL)); } } } else { exit($pdo->log->error('This script will optimise the tables.' . PHP_EOL . 'Argument 1:' . PHP_EOL . 'space ...: Optimise the tables that have free space > 5%.' . PHP_EOL . 'full ...: Force Optimise on all tables.' . PHP_EOL . 'analyze ...: Analyze tables to rebuild statistics.' . PHP_EOL . PHP_EOL . 'Argument 2:' . PHP_EOL . 'true|false ...: (Optional) Work on local tables? (good for replication).' . PHP_EOL . PHP_EOL . 'Argument 3:' . PHP_EOL . 'Table Name ...: (Optional) Name of a MySQL table, like releases' . PHP_EOL)); }
} } unset($value); $sql = "SHOW table status"; $tables = $pdo->query($sql); foreach ($tables as $row) { $tbl = $row['name']; if (preg_match('/collections_\\d+/', $tbl) || preg_match('/binaries_\\d+/', $tbl) || preg_match('/parts_\\d+/', $tbl) || preg_match('/missed_parts_\\d+/', $tbl) || preg_match('/\\d+_collections/', $tbl) || preg_match('/\\d+_binaries/', $tbl) || preg_match('/\\d+_parts/', $tbl) || preg_match('/\\d+_missed_parts_\\d+/', $tbl)) { $rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl)); if ($rel !== false) { echo $pdo->log->primary("Dropping {$tbl} completed."); } } } (new SphinxSearch())->truncateRTIndex('releases_rt'); $pdo->optimise(false, 'full'); echo $pdo->log->header("Deleting nzbfiles subfolders."); try { $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pdo->getSetting('nzbpath'), \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { if (basename($file) != '.gitignore' && basename($file) != 'tmpunrar') { $todo = $file->isDir() ? 'rmdir' : 'unlink'; @$todo($file); } } } catch (UnexpectedValueException $e) { echo $pdo->log->error($e->getMessage()); } echo $pdo->log->header("Deleting all images, previews and samples that still remain."); try { $dirItr = new \RecursiveDirectoryIterator(nZEDb_COVERS);
$runVar['commands']['_php'] = $show_time . " nice -n{$tmux_niceness} {$PHP}"; $runVar['commands']['_phpn'] = "nice -n{$tmux_niceness} {$PHP}"; $runVar['commands']['_python'] = $show_time . " nice -n{$tmux_niceness} {$PYTHON}"; $runVar['commands']['_sleep'] = "{$runVar['commands']['_phpn']} {$runVar['paths']['misc']}update/nix/tmux/bin/showsleep.php"; //spawn IRCScraper as soon as possible $tRun->runPane('scraper', $runVar); //get list of panes by name $runVar['panes'] = $tRun->getListOfPanes($runVar['constants']); //totals per category in db, results by parentID $catcntqry = "SELECT c.parentid AS parentid, COUNT(r.id) AS count FROM category c, releases r WHERE r.categoryid = c.id GROUP BY c.parentid"; //create timers and set to now $runVar['timers']['timer1'] = $runVar['timers']['timer2'] = $runVar['timers']['timer3'] = $runVar['timers']['timer4'] = $runVar['timers']['timer5'] = time(); $runVar['timers']['query']['tmux_time'] = $runVar['timers']['query']['split_time'] = $runVar['timers']['query']['init_time'] = $runVar['timers']['query']['proc1_time'] = $runVar['timers']['query']['proc2_time'] = $runVar['timers']['query']['proc3_time'] = $runVar['timers']['query']['split1_time'] = $runVar['timers']['query']['init1_time'] = $runVar['timers']['query']['proc11_time'] = $runVar['timers']['query']['proc21_time'] = $runVar['timers']['query']['proc31_time'] = $runVar['timers']['query']['tpg_time'] = $runVar['timers']['query']['tpg1_time'] = 0; // Analyze tables printf($pdo->log->info("\nAnalyzing your tables to refresh your indexes.")); $pdo->optimise(false, 'analyze', false, ['releases']); Misc::clearScreen(); $runVar['settings']['monitor'] = 0; $runVar['counts']['iterations'] = 1; $runVar['modsettings']['fc']['firstrun'] = true; $runVar['modsettings']['fc']['num'] = 0; $tblCount = "SELECT TABLE_ROWS AS count FROM information_schema.TABLES WHERE TABLE_NAME = :table AND TABLE_SCHEMA = " . $pdo->escapeString($db_name); $psTableRowCount = $pdo->Prepare($tblCount); while ($runVar['counts']['iterations'] > 0) { //check the db connection if ($pdo->ping(true) == false) { unset($pdo); $pdo = new Settings(); } $timer01 = time(); // These queries are very fast, run every loop -- tmux and site settings