From 337e3357db7a339260b78608436da4e1e7ebbade Mon Sep 17 00:00:00 2001
From: Ramon Novoa <rnovoa@artica.es>
Date: Fri, 22 Nov 2019 13:59:22 +0100
Subject: [PATCH] Non-intensive modules do not need to check a timestamp.

Ref pandora_enterprise#4660.
---
 .../win32/modules/pandora_module.cc           | 14 ++++++
 pandora_agents/win32/modules/pandora_module.h |  1 +
 .../win32/pandora_windows_service.cc          | 46 +++++++++++--------
 3 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc
index 7cbde21ca7..59e8af0a5b 100644
--- a/pandora_agents/win32/modules/pandora_module.cc
+++ b/pandora_agents/win32/modules/pandora_module.cc
@@ -1708,3 +1708,17 @@ void
 Pandora_Module::setExecutions (long executions) {
 	this->executions = executions;
 }
+
+/** 
+ * Checks if the module has intensive conditions.
+ * 
+ * @return true if the module's intensive condition list is not empty, false if it is.
+ */
+bool
+Pandora_Module::isIntensive () {
+	if (this->intensive_condition_list == NULL || this->intensive_condition_list->size () <= 0) {
+		return false;
+	}
+
+	return true;
+}
diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h
index 3b9d6c15a4..f38cac5f80 100644
--- a/pandora_agents/win32/modules/pandora_module.h
+++ b/pandora_agents/win32/modules/pandora_module.h
@@ -303,6 +303,7 @@ namespace Pandora_Modules {
 		time_t      getTimestamp ();
 		void        setIntensiveMatch (unsigned char intensive_match);
 		unsigned char getIntensiveMatch ();
+		bool        isIntensive ();
 
 	};
 }
diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc
index b62fc1f70d..73d0a5d482 100644
--- a/pandora_agents/win32/pandora_windows_service.cc
+++ b/pandora_agents/win32/pandora_windows_service.cc
@@ -1918,16 +1918,19 @@ Pandora_Windows_Service::pandora_run_broker (string config, long executions) {
 			}
 
 			/* Evaluate intensive conditions */
-			intensive_match = module->evaluateIntensiveConditions ();
-			if (intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
-				module->setNoOutput ();
-				this->broker_modules->goNext ();
-				continue;
-			}
-			module->setIntensiveMatch (intensive_match);
-			
-			if (module->getTimestamp () + module->getInterval () * this->interval_sec <= this->run_time) {
-				module->setTimestamp (this->run_time);
+			if (module->isIntensive()) {
+				intensive_match = module->evaluateIntensiveConditions ();
+				if (intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
+					module->setNoOutput ();
+					this->broker_modules->goNext ();
+					continue;
+				}
+
+				if (module->getTimestamp () + module->getInterval () * this->interval_sec <= this->run_time) {
+					module->setTimestamp (this->run_time);
+				}
+
+				module->setIntensiveMatch (intensive_match);
 			}
 			
 			/* Evaluate module conditions */
@@ -2038,16 +2041,19 @@ Pandora_Windows_Service::pandora_run (int forced_run) {
 			}
 
 			/* Evaluate intensive conditions */
-			intensive_match = module->evaluateIntensiveConditions ();
-			if (forced_run != 1 && intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
-				module->setNoOutput ();
-				this->modules->goNext ();
-				continue;
-			}
-			module->setIntensiveMatch (intensive_match);
-			
-			if (module->getTimestamp () + module->getInterval () * this->interval_sec <= this->run_time) {
-				module->setTimestamp (this->run_time);
+			if (module->isIntensive()) {
+				intensive_match = module->evaluateIntensiveConditions ();
+				if (forced_run != 1 && intensive_match == module->getIntensiveMatch () && module->getTimestamp () + module->getInterval () * this->interval_sec > this->run_time) {
+					module->setNoOutput ();
+					this->modules->goNext ();
+					continue;
+				}
+
+				if (module->getTimestamp () + module->getInterval () * this->interval_sec <= this->run_time) {
+					module->setTimestamp (this->run_time);
+				}
+
+				module->setIntensiveMatch (intensive_match);
 			}
 			
 			/* Evaluate module conditions */