TRy to speed up machine log file filtering, a=chris

Chris Pollett [2020-06-24 21:Jun:th]
TRy to speed up machine log file filtering, a=chris
Filename
src/controllers/MachineController.php
src/executables/QueueServer.php
src/models/MachineModel.php
diff --git a/src/controllers/MachineController.php b/src/controllers/MachineController.php
index 06127a162..dd12d1e04 100644
--- a/src/controllers/MachineController.php
+++ b/src/controllers/MachineController.php
@@ -221,18 +221,17 @@ class MachineController extends Controller implements CrawlConstants
                 $log_data = fread($fh, $len);
                 fclose($fh);
             }
-            if ($filter != "" && strlen($log_data) > 0) {
-                $log_lines = explode("\n", $log_data);
-                $out_lines = [];
-                foreach ($log_lines as $line) {
-                    if (stristr($line, $filter)) {
-                        $out_lines[] = $line;
-                    }
-                }
-                if (count($out_lines) == 0) {
-                    $out_lines[] = tl('machine_controller_nolines');
+            if (!empty($filter) && strlen($log_data) > 0) {
+                $quote_filter = preg_quote($filter);
+                if(preg_match_all('/.*' . $quote_filter . '.*\n/ui', $log_data,
+                    $matches)) {
+                    $log_data = implode("", ($matches[0] ?? []) );
+                } else {
+                    $log_data = "";
                 }
-                $log_data = implode("\n", $out_lines);
+            }
+            if (empty($log_data)) {
+                $log_data = tl('machine_controller_nolines') . "\n";
             }
         }
         $this->web_site->header("Content-Type: application/json");
diff --git a/src/executables/QueueServer.php b/src/executables/QueueServer.php
index 4f92d1b3f..a58aeae3e 100755
--- a/src/executables/QueueServer.php
+++ b/src/executables/QueueServer.php
@@ -449,13 +449,18 @@ class QueueServer implements CrawlConstants, Join
         $info[self::STATUS] = self::WAITING_START_MESSAGE_STATE;
         L\crawlLog("In queue loop!! {$this->server_name}", $this->process_name);
         if ($this->isAIndexer()) {
-            if ($this->isOnlyIndexer()) {
-                $_SERVER["NO_ROTATE_LOGS"] = true;
-            }
             $this->deleteOrphanedBundles();
         }
         L\crawlLog("PHP Version in use: " . phpversion());
         while (CrawlDaemon::processHandler()) {
+            if ($this->isOnlyIndexer()) {
+                $_SERVER["NO_ROTATE_LOGS"] = ((floor(time() / 30) % 2) == 0) ?
+                    true : false;
+            }
+            if ($this->isOnlyScheduler()) {
+                $_SERVER["NO_ROTATE_LOGS"] = ((floor(time() / 30) % 2) == 0) ?
+                    false : true;
+            }
             L\crawlLog("{$this->server_name} peak memory usage so far: ".
                 memory_get_peak_usage()."!!");
             $record_time = time();
diff --git a/src/models/MachineModel.php b/src/models/MachineModel.php
index f3205992d..eb1f22051 100644
--- a/src/models/MachineModel.php
+++ b/src/models/MachineModel.php
@@ -344,7 +344,7 @@ class MachineModel extends Model
      * @return string containing the last MachineController::LOG_LISTING_LEN
      *     bytes of the log record
      */
-    public function getLog($machine_name, $id, $type, $filter="")
+    public function getLog($machine_name, $id, $type, $filter = "")
     {
         $time = time();
         $session = md5($time . C\AUTH_KEY);
@@ -362,8 +362,8 @@ class MachineModel extends Model
         }
         if ($row) {
             $url = $row["URL"]. "?c=machine&a=log&time=$time".
-                "&session=$session&f=".urlencode($filter)."&type=$type&id=$id".
-                "&channel=" . $row['CHANNEL'];
+                "&session=$session&f=" . urlencode($filter) .
+                "&type=$type&id=$id&channel=" . $row['CHANNEL'];
             $log_page = FetchUrl::getPage($url);
             if (defined("ENT_SUBSTITUTE")) {
                 $log_data = htmlentities(L\webdecode(json_decode($log_page)),
ViewGit