Browse Source

added debug memory in AclQueryFeatures

Piotr Labudda 8 năm trước cách đây
mục cha
commit
3f0421e490
1 tập tin đã thay đổi với 29 bổ sung1 xóa
  1. 29 1
      SE/se-lib/AclQueryFeatures.php

+ 29 - 1
SE/se-lib/AclQueryFeatures.php

@@ -22,6 +22,8 @@ class AclQueryFeatures {
 	public $_legacyMode;
 	public $_legacyMode;
 	public $_selectLocalFields; // TODO: leave here or move to AclQueryBuilder? use join for perf?
 	public $_selectLocalFields; // TODO: leave here or move to AclQueryBuilder? use join for perf?
 	public $_selectRemote; // TODO: ...
 	public $_selectRemote; // TODO: ...
+	public $_dbgExecTime;
+	public $_instanceID;
 
 
 	public function __construct($acl, $params, $legacyMode = false) {
 	public function __construct($acl, $params, $legacyMode = false) {
 		$this->_acl = $acl;
 		$this->_acl = $acl;
@@ -32,6 +34,29 @@ class AclQueryFeatures {
 		// TODO: _legacyMode = ($from instanceof simple schema or another programmed objects)
 		// TODO: _legacyMode = ($from instanceof simple schema or another programmed objects)
 		$this->_selectLocalFields = null;
 		$this->_selectLocalFields = null;
 		$this->_selectRemote = null;
 		$this->_selectRemote = null;
+
+		$DBG_LOG_TO_FILE = true; // TODO: read from ENV or REQUEST
+		if ($DBG_LOG_TO_FILE) {
+			Lib::loadClass('DebugExecutionTime');
+			$this->_dbgExecTime = new DebugExecutionTime();
+			$this->_dbgExecTime->setLogFile('/tmp/se-dbg-exec-time--AclQueryFeatures.csv', $format = 'csv'); // $format: 'csv', 'json'
+			$this->_logToFile("from: '" . $this->_acl->getNamespace() . "'");
+		}
+	}
+
+	public function _logToFile($msg) {
+		if ($this->_dbgExecTime) {
+			$idInstance = $this->_getInstanceID();
+			$this->_dbgExecTime->logToFile("#{$idInstance}: {$msg}");
+		}
+	}
+	public function _getInstanceID() {
+		static $_INSTANCE_ID = 0;
+		if (!$this->_instanceID) {
+			$_INSTANCE_ID += 1;
+			$this->_instanceID = $_INSTANCE_ID;
+		}
+		return $this->_instanceID;
 	}
 	}
 
 
 	public function parseQueryValue($fieldName, $searchQuery, $fieldType = 'xsd:string') {
 	public function parseQueryValue($fieldName, $searchQuery, $fieldType = 'xsd:string') {
@@ -429,6 +454,7 @@ class AclQueryFeatures {
 	public function getParam($key) { return V::get($key, '', $this->_params); }
 	public function getParam($key) { return V::get($key, '', $this->_params); }
 
 
 	public function getItems() {
 	public function getItems() {
+		$this->_logToFile('getItems() ...');
 		if ($this->_legacyMode) return $this->_acl->getItems($this->_params);// TODO: array_map( $r => (array)$r )
 		if ($this->_legacyMode) return $this->_acl->getItems($this->_params);// TODO: array_map( $r => (array)$r )
 		// 'limit' => 10,
 		// 'limit' => 10,
 		//	'limitstart' => 0,
 		//	'limitstart' => 0,
@@ -453,7 +479,7 @@ class AclQueryFeatures {
 		DBG::log($select, 'array', "\$select is(TableAcl)=(".($this->_acl instanceof TableAcl).")");
 		DBG::log($select, 'array', "\$select is(TableAcl)=(".($this->_acl instanceof TableAcl).")");
 		// DBG::log($this->getQuery(), 'array', "\$select is(TableAcl)=(".($this->_acl instanceof TableAcl).") \$this->getQuery()");
 		// DBG::log($this->getQuery(), 'array', "\$select is(TableAcl)=(".($this->_acl instanceof TableAcl).") \$this->getQuery()");
 
 
-		return $this->fetchRowsRefs(
+		$items = $this->fetchRowsRefs(
 			$this->getQuery()
 			$this->getQuery()
 				->select($select)
 				->select($select)
 				->limit($limit)
 				->limit($limit)
@@ -461,6 +487,8 @@ class AclQueryFeatures {
 				->orderBy($sortBy)
 				->orderBy($sortBy)
 				->fetchAll()
 				->fetchAll()
 		);
 		);
+		$this->_logToFile('getItems() fetched.');
+		return $items;
 	}
 	}
 
 
 	public function getItem($primaryKey) { // TODO: throw exception if not found?
 	public function getItem($primaryKey) { // TODO: throw exception if not found?