Following on the patches in https://drupal.org/node/2220575 for inspiration I discovered that there is another point in the code path that triggers the same issue.
The function og_get_groups_by_user is called by several other functions in a single page load on the site I was testing with.

This patch utilizes the same functionality and idea as the one listed above to reduce entity_load() calls for og_membership relations.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

codexmas’s picture

japerry’s picture

Status: Active » Needs review

Awesome work Gord! Marking needs review, I'll add it to my list of patches to test against commons =)

Status: Needs review » Needs work

The last submitted patch, 1: avoid_entity_load_issue-2247557.patch, failed testing.

codexmas’s picture

FileSize
805 bytes
codexmas’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: avoid_entity_load_issue_2-2247557.patch, failed testing.

codexmas’s picture

FileSize
805 bytes
codexmas’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: 2247557-avoid-entity-load-issue-2.patch, failed testing.

codexmas’s picture

Status: Needs work » Needs review
FileSize
465 bytes

Testing baseline

Devin Carlson’s picture

Devin Carlson’s picture

An updated version of #7 to address the errors.

The last submitted patch, 7: 2247557-avoid-entity-load-issue-2.patch, failed testing.

ezra-g’s picture

Looks #12 passed testing, despite the erroneous comment in #12.

amitaibu’s picture

@ezra-g, I didn't understand your comment from #14 -- is the patch working for you?

joachim’s picture

+++ b/og.module
@@ -3522,14 +3522,13 @@ function og_get_groups_by_user($account = NULL, $group_type = NULL) {
-    $gids[$og_membership->group_type][$og_membership->gid] = $og_membership->gid;
...
+    $gids[$entity_type] = $group_id;

This change looks wrong. We can't see in the patch what happens to $gids later, but its structure appears to have changed.

iamjon’s picture

I applied the patch but unfortunately I noticed the calls to entity load actually increased. From 17,981 to 34,387
Also following what joachim mentioned I changed the patch to

$gids[$entity_type][$group_id] = $group_id;

But that threw out an error:
Warning: Illegal offset type in og_get_groups_by_user() (line 3551 of /home/phpteam/www/mythingsdev/mythings/modules/contrib/og/og.module).

However entity_load dropped drastically to 202 calls from 17,981.

Attaching a patch if anyone wants to investigate further

iamjon’s picture

Status: Needs review » Needs work

Changing status

The last submitted patch, 17: 2247557-avoid-entity-load-issue-13.patch, failed testing.

iamjon’s picture

FileSize
58.82 KB

I double checked. Patch #12 does not change the structure as per comment 16.
the structure stays the same

dpming $gids revels that $gids looks like

$gids['node'][161910]

The patch unfortunately does not lower the entity_load calls.