Skip to content

Commit

Permalink
[Migration/Notifications] Improved the performance of the notificatio…
Browse files Browse the repository at this point in the history
…n migration between 6.9 to 7.0.
  • Loading branch information
jstanden committed May 23, 2015
1 parent e8d097d commit 0047eee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion features/cerberusweb.core/patches/7.x/7.0.0.php
Expand Up @@ -525,7 +525,12 @@ function _700_migrate_inbox_buckets(&$params, $group_inboxes) {
$db->ExecuteMaster("ALTER TABLE notification ADD COLUMN activity_point VARCHAR(255) NOT NULL DEFAULT '', ADD INDEX (activity_point)");

// Convert existing notifications to being activity-based using the activity log
$db->ExecuteMaster("INSERT INTO notification (created_date, worker_id, is_read, context, context_id, activity_point, entry_json) SELECT n.created_date, n.worker_id, 0, n.context, n.context_id, al.activity_point, al.entry_json FROM notification n INNER JOIN context_activity_log al ON (n.context=al.target_context AND n.context_id=al.target_context_id) WHERE n.is_read = 0 AND al.created BETWEEN CAST(n.created_date-1 AS unsigned) AND CAST(n.created_date+1 AS unsigned)");
$db->ExecuteMaster("INSERT INTO notification (created_date, worker_id, is_read, context, context_id, activity_point, entry_json) ".
"SELECT n.created_date, n.worker_id, 0, n.context, n.context_id, al.activity_point, al.entry_json ".
"FROM notification n ".
"INNER JOIN context_activity_log al ON (n.context=al.target_context AND n.context_id=al.target_context_id) ".
"WHERE n.is_read = 0 AND al.created = n.created_date"
);

// Delete the old notifications
$db->ExecuteMaster("DELETE FROM notification WHERE activity_point = ''");
Expand Down

0 comments on commit 0047eee

Please sign in to comment.