This query is taking 35 minutes on a site with 65k rows in heartbeat_activity and 180k rows in og_ancestry.
+----+-------------+-----------------+--------+---------------------------------------+------------+---------+---------------------------+--------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------+--------+---------------------------------------+------------+---------+---------------------------+--------+------------------------------------------------+
| 1 | SIMPLE | ua | ref | timestamp,uid,uid_target,nid,language | language | 39 | const | 38057 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | hm | ref | message_id | message_id | 753 | example.ua.message_id | 1 | |
| 1 | SIMPLE | ua_users | eq_ref | PRIMARY | PRIMARY | 4 | example.ua.uid | 1 | Using where |
| 1 | SIMPLE | ua_target_users | eq_ref | PRIMARY | PRIMARY | 4 | example.ua.uid_target | 1 | Using where |
| 1 | SIMPLE | oa | ALL | PRIMARY | NULL | NULL | NULL | 120219 | Range checked for each record (index map: 0x1) |
+----+-------------+-----------------+--------+---------------------------------------+------------+---------+---------------------------+--------+------------------------------------------------+
5 rows in set (0.00 sec)
Removing the join on og_ancestry gets it down to 0.6 seconds.
There is still a filesort on the heartbeat_activity table, but that can be fixed with ALTER TABLE heartbeat_activity ADD INDEX language_timestamp (language, timestamp);
To replace the join on og_ancestry I'm thinking it'd be possible for og_activity to add a column to heartbeat_activity - adding a 'in_group' flag to the table - this would be evaluated in PHP before adding records, then it's just an extra condition on that table rather than the join + range.
Will be a couple of days before I'm able to work on this most likely but wanted to get the issue open.
Comment | File | Size | Author |
---|---|---|---|
#7 | heartbeat_og_1267500.patch | 4.24 KB | catch |
Comments
Comment #1
Stalski CreditAttribution: Stalski commentedCould it be you are using drupal6? I have not written an implementation for og activity within heartbeat yet. I was even wondering if that's needed, since in drupal7 the views approach provides enough features.
Or are you creating a custom module that provides this integration? In that case, great!
- Edit - Actually it must be drupal6 since {heartbeat_messages} does not exist anymore (taken over by ctools export api)
Comment #2
catchSorry this is Drupal 6, I posted it against 7.x-1.x without looking in the branch out of habit.
Comment #3
Stalski CreditAttribution: Stalski commentedThe change is actually not that big. It's certainly something to fix.
Comment #4
Stalski CreditAttribution: Stalski commentedThe change is actually not that big. It's certainly something to fix.
Comment #5
catchI'm working on this.
Comment #6
Stalski CreditAttribution: Stalski commentedThere is an issue to port this functionality to D7, so the moment you do and it gets accepted, I'll take time to port this as a drupal7 submodule.
Thx catch
Comment #7
catchOK here's the patch:
og_activity does this:
hook_schema_alter() the new in_group column
Add index for in_group, language, timestamp.
hook_heartbeat_activity_log() to add the in_group value to log items.
I also added an update to set this for existing records.
Tested both the update and creating a node in a group. Seems to be working OK.
Comment #8
Stalski CreditAttribution: Stalski commentedAwesome. Thx a lot.
Tested and works great. This is pushed to git already.
Comment #9
Stalski CreditAttribution: Stalski commented- Added the in_group where clause in the query used when selecting "groupsactivity" in views UI.
- Fixed og_activity_heartbeat_activity_log so it takes existing "nid"
Comment #10
Stalski CreditAttribution: Stalski commentedSaw another issue. Code currently:
Seems to be working as expected now.
Comment #11
Stalski CreditAttribution: Stalski commentedHmm after some more extending testing, it did not work properly.
This is a the new code. A quick peek review would be great.
Comment #12
catchany reason you're not checking nid against nid_target?
Comment #13
Stalski CreditAttribution: Stalski commentedHehe, indeed, that did not work either.
It works in all cases and languages now (with uaid it worked only for last inserted record).
In previous patches , nothing was being done with $in_group. So this seems to work and looks Ok to me.