We noticed a load on our server and did a little digging.

I found that because of the difference to 6.x-1.x in stormteam, there could be many additional node_loads.
In our case we had around 1000 queries, when adding a storm node or if we have a assignment select box - because of the storm_dashboard module, this is on every page the case... (i also should do some performance fixes there...)

To the concrete Problem:
storm_get_assignment_options does a node_load on every team and the team does a node_load on every person. In our case around 300 teams, 100persons, a lot of combinations and a lot of modules which maybe does something on node_load.

We should fix this somehow.
I will post a patch with a proposal.

Comments

kfritsche’s picture

Status: Active » Needs review
StatusFileSize
new3.15 KB

This patch changes two things:

In stormteam_load it loads the node title directly and doesn't use node_load there. I think it is overkill to load for each person the complete node, because on when loading a stormperson, there a lot of additional requests.

The end of storm_get_assignment_options is rewritten. It now does one SQL which covers all the code and additional queries there. Its now a little bit more complex query, but it is much better and faster than 500 additional small queries.

With all this i got it from 1000 to 300 queries down.

juliangb’s picture

Sounds like a sensible change. (I have read through the patch but haven't tested.)

Now that the query is less intuitive, I wonder whether it'd be worth putting some additional comments in the code to explain what is happening?

kfritsche’s picture

StatusFileSize
new4.19 KB

Added two minor comments, i hope this explains it ;)

Also initialized the members array, because of warnings while accessing these variables.

Status: Needs review » Needs work

The last submitted patch, stormteam_performance-1389998-3.patch, failed testing.

kfritsche’s picture

Status: Needs work » Needs review
StatusFileSize
new4.66 KB

Since when the Drupal Test Bot complains about notices?
I looked in the history, this notice is there from the beginning of the stormteam module ;)

Fixing this now for the Test Bot :)

juliangb’s picture

Status: Needs review » Needs work
+++ b/storm.module
@@ -1047,7 +1047,12 @@ function storm_get_assignment_options($organization_nid = 0, $project_nid = 0) {
+              $add = TRUE;
+              // do not add deactivated persons
+              if (is_array($node->members_deactivated_array) && array_key_exists($nid, $node->members_deactivated_array)) {
+                $add = false;
+              }
+              if ($add) {

I wonder if it read better (more intuitively) with the !array_key_exists line? (amended for the is_array check)

+++ b/storm.module
@@ -1091,32 +1096,34 @@ function storm_get_assignment_options($organization_nid = 0, $project_nid = 0) {
+    // do not add teams, which we already added
+    if (!empty($options[$teams])) {
+      $where[] = "ste.nid NOT IN (".db_placeholders($options[$teams]).")";
+      $args = array_merge($args, array_keys($options[$teams]));
+    }
+    // only add teams, which have at least the same people in it
+    if (!empty($organization_nid) && !empty($options[$people])) {
+      $where[] = "ste.mnid IN (".db_placeholders($options[$people]).")";
+      $args = array_merge($args, array_keys($options[$people]));
+      // without HAVING we get all teams, with at least on person, but we want that all people are in the other teams

Sorry, I don't really understand the comments here. Can you expand on them at all?

kfritsche’s picture

Do you think, something like this would be better?
We need this second check, otherwise it returns no people, if members_deactivated_array is not an array.

if ((is_array($node->members_deactivated_array) && array_key_exists($nid, $node->members_deactivated_array)) || (!is_array($node->members_deactivated_array))) {
  $options[$people][$nid] = check_plain($name);
}

On the otherhand, maybe we can remove this is_array check there because of the changes in stormteam_load, this should be an array.

I will change the comments again, have to think of something clever to write there. The SQL should only get teams with all persons, we already added to the assignment select box. Otherwise we get for every assignment select field all teams. The idea was back then and still is, that we only add teams, which have the same persons in it as the persons which we can assign this. Except if there is no organization given, then we want all teams, because we can't/won't filter this assignment select box.

I will make a little example here, so that every one can understand it (i hope so ;) ):
a number of persons - P1, P2, ...
3 Teams - TeamA (all even P2, P4, ..), TeamB (all odd P1, P3), TeamC (first ten P1-P10), Team D (all persons)
In the filter form, we do not have any organization given, so this functions returns all teams (A,B,C,D).
In the ticket form, we have a organization given, so we want to limit the teams. As teams aren't assigned to an organization or project, the idea is, to add all teams there which have all possible persons in it, which can be assigned to this ticket.
e.g. the ticket can be assigned to P1, P3, P5, P6, P8, so this SQL returns TeamC and TeamD - because P6,P8 are not in Team A and P1,P3,P5 are not in TeamB.

With the HAVING COUNT we can set how many people must be in the other team. At the moment this must be all persons, but if we like we can change this to half of the people. If we do so, in my little example it also should return TeamA, because half of the people - P1,P3,P5 (3 out of 5) are assigned to this. This would be a change to the current behaivor. I added the maybe confusing comment there, to know when someone asks for this, we know we have to change only the count there.

juliangb’s picture

Yes, I'd be in favour of removing the is_array check - as you say, with the change to stormteam_load, it should always be an array.

I think I see what is happening now - the extra having clause was confusing me somewhat! I'll think about a way of putting this in comments and post again with a suggestion.

kfritsche’s picture

StatusFileSize
new4.46 KB

Changed the array_key_exists and the comments again.

juliangb’s picture

Status: Needs work » Needs review

For testbot.

juliangb’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.