Skip to content

Use the same indexing database throughout #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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