summaryrefslogtreecommitdiff
path: root/inc/functions.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2016-05-08 13:20:00 +0200
committerczaks <marcin@6irc.net>2016-05-08 13:23:41 +0200
commit12e6aba5d4a2965591b3df76e4f6c19e35475700 (patch)
treeee38c5ac853427ac7af904f5631e755a081c7d90 /inc/functions.php
parente2653754750917035b79e62b07d286b3a56cf9ca (diff)
(2/2) advanced build. implement a daemon that will build static pages.
implement a queue and a lock. fix notice in bans. and it even works! the daemon is basic right now, it could work in a mode that it will defer building certain pages until a certain time.
Diffstat (limited to 'inc/functions.php')
-rwxr-xr-xinc/functions.php40
1 files changed, 35 insertions, 5 deletions
diff --git a/inc/functions.php b/inc/functions.php
index 8329e774..0cfdb72f 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -19,6 +19,8 @@ require_once 'inc/database.php';
require_once 'inc/events.php';
require_once 'inc/api.php';
require_once 'inc/mod/auth.php';
+require_once 'inc/lock.php';
+require_once 'inc/queue.php';
require_once 'inc/polyfill.php';
@include_once 'inc/lib/parsedown/Parsedown.php'; // fail silently, this isn't a critical piece of code
@@ -93,6 +95,8 @@ function loadConfig() {
'db',
'api',
'cache',
+ 'lock',
+ 'queue',
'cookies',
'error',
'dir',
@@ -1749,7 +1753,6 @@ function buildJavascript() {
function checkDNSBL() {
global $config;
-
if (isIPv6())
return; // No IPv6 support yet.
@@ -2806,17 +2809,17 @@ function generation_strategy($fun, $array=array()) { global $config;
$action = false;
foreach ($config['generation_strategies'] as $s) {
- if ($strategy = $s($fun, $array)) {
+ if ($action = $s($fun, $array)) {
break;
}
}
- switch ($strategy[0]) {
+ switch ($action[0]) {
case 'immediate':
return 'rebuild';
case 'defer':
// Ok, it gets interesting here :)
- Queue::add(serialize(array('build', $fun, $array)));
+ get_queue('generate')->push(serialize(array('build', $fun, $array, $action)));
return 'ignore';
case 'build_on_load':
return 'delete';
@@ -2832,5 +2835,32 @@ function strategy_smart_build($fun, $array) {
}
function strategy_sane($fun, $array) { global $config;
- return false;
+ // Well, ideally a sane strategy would involve a more stringent checking,
+ // but let's at least have something to get the ball rolling :^)
+
+ if (php_sapi_name() == 'cli') return false;
+ else if (isset($_POST['mod']) || isset($_POST['json_response'])) return false;
+ else if ($fun == 'sb_thread' || ($fun == 'sb_board' && $array[1] == 1)) return array('immediate');
+ else return false;
+}
+
+// My first, test strategy.
+function strategy_first($fun, $array) {
+ switch ($fun) {
+ case 'sb_thread':
+ return array('defer');
+ case 'sb_board':
+ if ($array[1] > 8) return array('build_on_load');
+ else return array('defer');
+ case 'sb_api':
+ return array('defer');
+ case 'sb_catalog':
+ return array('defer');
+ case 'sb_recent':
+ return array('build_on_load');
+ case 'sb_sitemap':
+ return array('build_on_load');
+ case 'sb_ukko':
+ return array('defer');
+ }
}