From f8cfe1d2fc610f4336247ed47a046d04ef24a0ec Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sat, 14 Sep 2019 17:20:11 +0100 Subject: [PATCH] Only index if docRoot mtime changed or diff to ts --- lib/indexer.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/indexer.php b/lib/indexer.php index 2e3707c..728d334 100644 --- a/lib/indexer.php +++ b/lib/indexer.php @@ -9,9 +9,9 @@ $indexableFileExts = ["php", "js", "coffee", "ts", "rb", "py", "sql", "erl", "ja $prevIndexData = []; // If we have a data/index.php file -if (file_exists("../data/index.php")) { +if (file_exists($docRoot.$ICEcoderDir."/data/index.php")) { // Get serialized array back out of PHP file inside a comment block as prevIndexData - $prevIndexData = file_get_contents("../data/index.php"); + $prevIndexData = file_get_contents($docRoot.$ICEcoderDir."/data/index.php"); if (strpos($prevIndexData, "", "", $prevIndexData); @@ -146,14 +146,25 @@ function phpGrep($path, $base) { return $ret; } -// Start running function to index data -$results = phpGrep($docRoot.$iceRoot, $docRoot.$iceRoot); +// If something in the doc root changed, we can do an index... +if (stat($docRoot)['mtime'] !== $prevIndexData["timestamps"]["indexed"]) { + // Start a new indexData for this run + $indexData["timestamps"] = [ + "indexed" => stat($docRoot)['mtime'] + ]; -// Overlay indexData ontop of prevIndexData -$output = array_replace_recursive($prevIndexData, $indexData); + // Start running function to index data + $results = phpGrep($docRoot.$iceRoot, $docRoot.$iceRoot); -// Store the serialized array in PHP comment block for next time -file_put_contents($docRoot.$ICEcoderDir."/data/index.php", ""); + // Overlay indexData ontop of prevIndexData + $output = array_replace_recursive($prevIndexData, $indexData); + + // Store the serialized array in PHP comment block for next time + file_put_contents($docRoot.$ICEcoderDir."/data/index.php", ""); +// Else it's the same as last time so do nothing... +} else { + $output = $prevIndexData; +} // Output the JSON echo json_encode($output, JSON_PRETTY_PRINT);