diff --git a/phpdotnet/phd/Format.php b/phpdotnet/phd/Format.php index 2317deba..1754f914 100644 --- a/phpdotnet/phd/Format.php +++ b/phpdotnet/phd/Format.php @@ -63,14 +63,8 @@ abstract class Format extends ObjectStorage protected $CURRENT_ID = ""; public function __construct() { - $sqlite = Config::indexcache(); - if (!$sqlite) { - if (file_exists(Config::output_dir() . "index.sqlite")) { - $sqlite = new \SQLite3(Config::output_dir() . 'index.sqlite'); - } - } - if ($sqlite) { - $this->sqlite = $sqlite; + if (Config::indexcache()) { + $this->sqlite = Config::indexcache(); $this->sortIDs(); } } diff --git a/phpdotnet/phd/functions.php b/phpdotnet/phd/functions.php index 013d2d2d..dff19f29 100644 --- a/phpdotnet/phd/functions.php +++ b/phpdotnet/phd/functions.php @@ -195,12 +195,9 @@ function errh($errno, $msg, $file, $line, $ctx = null) { * * @return boolean True if indexing is required. */ -function requireIndexing(Config $config, ?\SQLite3 $db = null): bool { - if ($db === null) { - $indexfile = $config->output_dir() . 'index.sqlite'; - if (!file_exists($indexfile)) { - return true; - } +function requireIndexing(Config $config): bool { + if (! $config->indexcache()) { + return true; } if ($config->no_index()) { @@ -211,9 +208,8 @@ function requireIndexing(Config $config, ?\SQLite3 $db = null): bool { return true; } - if ($db === null) { - $db = new \SQLite3($indexfile); - } + $db = $config->indexcache(); + $indexingCount = $db->query('SELECT COUNT(time) FROM indexing') ->fetchArray(SQLITE3_NUM); if ($indexingCount[0] == 0) { diff --git a/render.php b/render.php index e523ae9f..4e66edba 100644 --- a/render.php +++ b/render.php @@ -72,15 +72,15 @@ exit(0); } -function make_reader() { +function make_reader(Config $config) { //Partial Rendering $idlist = Config::render_ids() + Config::skip_ids(); if (!empty($idlist)) { v("Running partial build", VERBOSE_RENDER_STYLE); $parents = []; - if (file_exists(Config::output_dir() . "index.sqlite")) { - $sqlite = new \SQLite3(Config::output_dir() . "index.sqlite"); + if ($config->indexcache()) { + $sqlite = $config->indexcache(); // Fetch all ancestors of the ids we should render foreach(Config::render_ids() as $p => $v) { do { @@ -115,33 +115,26 @@ function make_reader() { $readerOpts |= LIBXML_XINCLUDE; } -if (file_exists(Config::output_dir() . 'index.sqlite')) { - $db = new \SQLite3(Config::output_dir() . 'index.sqlite'); +if (Config::memoryindex()) { + $db = new \SQLite3(":memory:"); } else { - $db = null; + $db = new \SQLite3(Config::output_dir() . 'index.sqlite'); } +Config::set_indexcache($db); + // Indexing -if (requireIndexing(new Config, $db)) { +if (requireIndexing(new Config)) { v("Indexing...", VERBOSE_INDEXING); - if (Config::memoryindex()) { - $db = new \SQLite3(":memory:"); - } else { - $db = $db ?? new \SQLite3(Config::output_dir() . 'index.sqlite'); - } // Create indexer $indexRepository = new IndexRepository($db); $format = new Index($indexRepository); $render->attach($format); - $reader = make_reader(); + $reader = make_reader(new Config); $reader->open(Config::xml_file(), NULL, $readerOpts); $render->execute($reader); - if (Config::memoryindex()) { - Config::set_indexcache($db); - } - $render->detach($format); v("Indexing done", VERBOSE_INDEXING); @@ -164,7 +157,7 @@ function make_reader() { } // Render formats -$reader = make_reader(); +$reader = make_reader(new Config); $reader->open(Config::xml_file(), NULL, $readerOpts); foreach($render as $format) { $format->notify(Render::VERBOSE, true);