I would like to improve the performance of spaces_og by avoiding a node_load or delaying it until it is required through the use of a node injector class which provides node properties as required through direct queries or through a full node_load.

Comments

pdrake’s picture

Status: Active » Needs review
StatusFileSize
new2.38 KB

Here's a patch which delays node_load until it is required and provides the og_private property without requiring a full node_load. This pattern could be extended to provide other properties via a direct query as well if other opportunities for performance improvements are identified.

glennpratt’s picture

Interesting idea, I've done the same for debugging and refactoring, but for performance is a pretty cool idea.

To be even more seamless, should probably implement the other common magic methods

__isset()
__unset()

and extend stdClass.

Not sure if there is a way to handle things like print_r, cast to array, serialize, etc, but that might be OK.

pdrake’s picture

I have taken your suggestions and implemented them. Certainly, the injected group object could be used in ways that are unintended, with side-effects, but I believe that the magic methods implemented cover all of the existing ways in which spaces itself is using the group object.

pdrake’s picture

Ah, missed a function comment in that last patch. This patch is functionally the same, only adding the missing comment.

glennpratt’s picture

Status: Needs review » Needs work
+++ b/spaces_og/plugins/space_og.incundefined
@@ -191,3 +191,117 @@ class space_og extends space_type_purl {
+  public function __isset($property) {

Could probably be

  return ($this->__get($property) === NULL);
pdrake’s picture

Based on the suggestion in #5.

travist’s picture

+++ b/spaces_og/plugins/space_og.incundefined
@@ -191,3 +191,106 @@ class space_og extends space_type_purl {
+    elseif (!$this->loaded) {
+      switch ($requested_property) {
+        case 'og_private':
+          $sql = 'SELECT og_private FROM {og} WHERE nid = %d';
+          $properties = db_fetch_array(db_query($sql, $this->node->nid));
+          foreach ($properties as $property => $value) {
+            $this->node->$property = $value;
+          }

If it isn't loaded, and the first property it asks for is $node->og_private, this would probably fatal since $this->node would still be null at this point. I think you should at least pre-define $this->node to be a new stdClass() to avoid this.

travist’s picture

Disregard ^.... Didn't see you initialized it in the constructor.

pdrake’s picture

This resolves a bug introduced in an earlier patch and PHP notices when accessing non-existent $node properties.

pdrake’s picture

To help address contrib/custom code that may regard $space->group as a full node object, I have reworked the __get magic method definition a bit.

pdrake’s picture

Status: Needs work » Closed (fixed)

This is now available as a stand-alone module, complementing spaces_og: http://drupal.org/project/spaces_og_accelerated