From 61371f77ceed2184aef4e1494d2b9e625afd9e90 Mon Sep 17 00:00:00 2001 From: 8chan Date: Thu, 19 Feb 2015 19:14:24 -0800 Subject: [PATCH] rebuild2 - multithreaded rebuild script --- tools/rebuild2.php | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100755 tools/rebuild2.php diff --git a/tools/rebuild2.php b/tools/rebuild2.php new file mode 100755 index 00000000..2945460c --- /dev/null +++ b/tools/rebuild2.php @@ -0,0 +1,140 @@ +#!/usr/bin/php +clearCacheFiles(); +} + +if($options['themes']) { + echo "Regenerating theme files...\n"; + rebuildThemes('all'); +} + +if($options['js']) { + echo "Generating Javascript file...\n"; + buildJavascript(); +} + +$main_js = $config['file_script']; + +$boards = listBoards(); +//$boards = array(array('uri'=>'test'), array('uri'=>'tester'), array('uri'=>'testing')); +$boards_m = array_chunk($boards, floor(sizeof($boards)/$options['processes'])); + +function doboard($board) { + global $global_locale, $config, $main_js, $options; + $config['mask_db_error'] = false; + if (!$options['api']) $config['api']['enabled'] = false; + + echo "Opening board /{$board['uri']}/...\n"; + // Reset locale to global locale + $config['locale'] = $global_locale; + init_locale($config['locale'], 'error'); + openBoard($board['uri']); + $config['try_smarter'] = false; + + if($config['file_script'] != $main_js && $options['js']) { + // different javascript file + echo "(/{$board['uri']}/) Generating Javascript file...\n"; + buildJavascript(); + } + + + if ($options['indexes']) { + echo "(/{$board['uri']}/) Creating index pages...\n"; + buildIndex(); + } + + if($options['postmarkup']) { + $query = query(sprintf("SELECT `id` FROM ``posts_%s``", $board['uri'])) or error(db_error()); + while($post = $query->fetch()) { + echo "(/{$board['uri']}/) Rebuilding #{$post['id']}...\n"; + rebuildPost($post['id']); + } + } + + if ($options['threads']) { + $query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); + while($post = $query->fetch()) { + echo "(/{$board['uri']}/) Rebuilding #{$post['id']}...\n"; + @buildThread($post['id']); + } + } +} + +$children = array(); +foreach ($boards_m as $i => $bb) { + $pid = pcntl_fork(); + + if ($pid == -1) { + die('Fork failed?'); + } else if ($pid) { + echo "Started PID #$pid...\n"; + $children[] = $pid; + } else { + unset($pdo); + $i = 0; + $total = sizeof($bb); + sql_open(); + foreach ($bb as $i => $b) { + $i++; + doboard($b); + echo "I'm on board $i/$total\n"; + } + break; + } +} + + +printf("Complete! Took %g seconds\n", microtime(true) - $start); + +unset($board); + +foreach ($children as $child) { + pcntl_waitpid($child, $status); + unset($children[$child]); +} + +//modLog('Rebuilt everything using tools/rebuild.php');