Permalink
Browse files

perf(engine): only update attributes/metadata if value is changed

  • Loading branch information...
jdalsem committed Jun 26, 2015
1 parent c1f0ff9 commit 8295e70a2c8381f15158a919a1870d279228bdc0
Showing with 22 additions and 18 deletions.
  1. +22 −18 engine/classes/ElggEntity.php
@@ -80,14 +80,14 @@
/**
* Tells how many tables are going to need to be searched in order to fully populate this object
*
*
* @var int
*/
protected $tables_split;
/**
* Tells how many tables describing object have been loaded thus far
*
*
* @var int
*/
protected $tables_loaded;
@@ -183,18 +183,22 @@ public function __clone() {
/**
* Set an attribute or metadata value for this entity
*
*
* Anything that is not an attribute is saved as metadata.
*
* @warning Metadata set this way will inherit the entity's owner and
*
* @warning Metadata set this way will inherit the entity's owner and
* access ID. If you want more control over metadata, use \ElggEntity::setMetadata()
*
*
* @param string $name Name of the attribute or metadata
* @param mixed $value The value to be set
* @return void
* @see \ElggEntity::setMetadata()
*/
public function __set($name, $value) {
if ($this->$name === $value) {
// quick return if value is not changing
return;
}
if (array_key_exists($name, $this->attributes)) {
// Certain properties should not be manually changed!
switch ($name) {
@@ -239,13 +243,13 @@ public function set($name, $value) {
/**
* Get an attribute or metadata value
*
*
* If the name matches an attribute, the attribute is returned. If metadata
* does not exist with that name, a null is returned.
*
* This only returns an array if there are multiple values for a particular
* $name key.
*
*
* @param string $name Name of the attribute or metadata
* @return mixed
*/
@@ -275,14 +279,14 @@ public function get($name) {
/**
* Get the entity's display name
*
*
* @return string The title or name of this entity.
*/
abstract public function getDisplayName();
/**
* Sets the title or name of this entity.
*
*
* @param string $displayName The title or name of this entity.
* @return void
*/
@@ -1100,7 +1104,7 @@ public function canDelete($user_guid = 0) {
_elgg_services()->logger->warning($message);
return false;
}
}
$return = $this->canEdit($user_guid);
@@ -1435,7 +1439,7 @@ public function setURL($url) {
public function getIconURL($params = array()) {
if (is_array($params)) {
$size = elgg_extract('size', $params, 'medium');
} else {
} else {
$size = is_string($params) ? $params : 'medium';
$params = array();
}
@@ -1830,7 +1834,7 @@ protected function load($guid) {
/**
* Stores non-attributes from the loading of the entity as volatile data
*
*
* @param array $data Key value array
* @return void
*/
@@ -1847,7 +1851,7 @@ protected function loadAdditionalSelectValues(array $data) {
* @internal This is used when the same entity is selected twice during a
* request in case different select clauses were used to load different data
* into volatile data.
*
*
* @param \stdClass $row DB row with new entity data
* @return bool
* @access private
@@ -2035,7 +2039,7 @@ public function delete($recursive = true) {
}
// first check if we can delete this entity
// NOTE: in Elgg <= 1.10.3 this was after the delete event,
// NOTE: in Elgg <= 1.10.3 this was after the delete event,
// which could potentially remove some content if the user didn't have access
if (!$this->canDelete()) {
return false;
@@ -2150,7 +2154,7 @@ public function toObject() {
/**
* Prepare an object copy for toObject()
*
*
* @param \stdClass $object Object representation of the entity
* @return \stdClass
*/
@@ -2273,7 +2277,7 @@ public function getCalendarStartTime() {
/**
* Returns the end timestamp.
*
*
* @return int
* @deprecated 1.9
*/
@@ -2520,7 +2524,7 @@ public function deleteAccessCollectionMemberships() {
/**
* Remove all access collections owned by this entity
*
*
* @return bool
* @since 1.11
*/

0 comments on commit 8295e70

Please sign in to comment.