Skip to content

Commit

Permalink
Revert "Use the same indexing database throughout (#118)"
Browse files Browse the repository at this point in the history
This doesn't seem to create the DB properly and is failing the builds.

This reverts commit ef13e91.
  • Loading branch information
Girgias committed Apr 25, 2024
1 parent e7a6c0c commit f93552a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
10 changes: 8 additions & 2 deletions phpdotnet/phd/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ abstract class Format extends ObjectStorage
protected $CURRENT_ID = "";

public function __construct() {
if (Config::indexcache()) {
$this->sqlite = Config::indexcache();
$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;
$this->sortIDs();
}
}
Expand Down
14 changes: 9 additions & 5 deletions phpdotnet/phd/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,12 @@ function errh($errno, $msg, $file, $line, $ctx = null) {
*
* @return boolean True if indexing is required.
*/
function requireIndexing(Config $config): bool {
if (! $config->indexcache()) {
return true;
function requireIndexing(Config $config, ?\SQLite3 $db = null): bool {
if ($db === null) {
$indexfile = $config->output_dir() . 'index.sqlite';
if (!file_exists($indexfile)) {
return true;
}
}

if ($config->no_index()) {
Expand All @@ -208,8 +211,9 @@ function requireIndexing(Config $config): bool {
return true;
}

$db = $config->indexcache();

if ($db === null) {
$db = new \SQLite3($indexfile);
}
$indexingCount = $db->query('SELECT COUNT(time) FROM indexing')
->fetchArray(SQLITE3_NUM);
if ($indexingCount[0] == 0) {
Expand Down
29 changes: 18 additions & 11 deletions render.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@
exit(0);
}

function make_reader(Config $config) {
function make_reader() {
//Partial Rendering
$idlist = Config::render_ids() + Config::skip_ids();
if (!empty($idlist)) {
v("Running partial build", VERBOSE_RENDER_STYLE);

$parents = [];
if ($config->indexcache()) {
$sqlite = $config->indexcache();
if (file_exists(Config::output_dir() . "index.sqlite")) {
$sqlite = new \SQLite3(Config::output_dir() . "index.sqlite");
// Fetch all ancestors of the ids we should render
foreach(Config::render_ids() as $p => $v) {
do {
Expand Down Expand Up @@ -116,26 +116,33 @@ function make_reader(Config $config) {
$readerOpts |= LIBXML_XINCLUDE;
}

if (Config::memoryindex()) {
$db = new \SQLite3(":memory:");
} else {
if (file_exists(Config::output_dir() . 'index.sqlite')) {
$db = new \SQLite3(Config::output_dir() . 'index.sqlite');
} else {
$db = null;
}

Config::set_indexcache($db);

// Indexing
if (requireIndexing(new Config)) {
if (requireIndexing(new Config, $db)) {
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(new Config);
$reader = make_reader();
$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 @@ -158,7 +165,7 @@ function make_reader(Config $config) {
}

// Render formats
$reader = make_reader(new Config);
$reader = make_reader();
$reader->open(Config::xml_file(), NULL, $readerOpts);
foreach($render as $format) {
$format->notify(Render::VERBOSE, true);
Expand Down

0 comments on commit f93552a

Please sign in to comment.