Skip to content

Commit

Permalink
Use the same indexing database throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
haszi committed Apr 25, 2024
1 parent 40e35fe commit f202374
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 35 deletions.
10 changes: 2 additions & 8 deletions phpdotnet/phd/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
14 changes: 5 additions & 9 deletions phpdotnet/phd/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down
29 changes: 11 additions & 18 deletions render.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f202374

Please sign in to comment.