From daeedae81cf21c73a84334b921dc4feab08fd2e6 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 2 Oct 2019 08:50:11 +0100 Subject: [PATCH] Check banned file first, timestamps before index --- lib/indexer.php | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/indexer.php b/lib/indexer.php index 728d334..efdebef 100644 --- a/lib/indexer.php +++ b/lib/indexer.php @@ -70,7 +70,9 @@ function phpGrep($path, $base) { $bFile = false; // Exclude banned files for ($i=0;$i stat($docRoot)['mtime'] - ]; +// If we don't have a timestamp passed in or it's not the same as what's in the index... +if (!isset($_GET['timestamp']) || $_GET['timestamp'] != $prevIndexData["timestamps"]["indexed"]) { + // If something in the doc root changed, we can do an index... + if ($prevIndexData["timestamps"]["indexed"] !== stat($docRoot)['mtime']) { + // Start a new indexData for this run + $indexData["timestamps"] = [ + "indexed" => stat($docRoot)['mtime'], + "browser" => $_GET['timestamp'] ?? 0, + "changed" => true + ]; - // Start running function to index data - $results = phpGrep($docRoot.$iceRoot, $docRoot.$iceRoot); + // Start running function to index data + $results = phpGrep($docRoot.$iceRoot, $docRoot.$iceRoot); - // Overlay indexData ontop of prevIndexData - $output = array_replace_recursive($prevIndexData, $indexData); + // 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", ""); + // Store the serialized array in PHP comment block for next time + file_put_contents($docRoot.$ICEcoderDir."/data/index.php", ""); + // Output what we have in our index... + } else { + $output = $prevIndexData; + } // Else it's the same as last time so do nothing... } else { - $output = $prevIndexData; + $output = [ + "timestamps" => [ + "indexed" => stat($docRoot)['mtime'], + "browser" => (int) $_GET['timestamp'], + "changed" => false + ] + ]; } // Output the JSON