Commit eefcf77e authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Making the notification batching system also batch the data pulled from the DB"

parents 2f2d9c18 876305ec
......@@ -810,13 +810,39 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
return;
}
$subscribers = get_records_sql_assoc('
SELECT "user" AS subscriber, \'topic\' AS type, "key" FROM {interaction_forum_subscription_topic} WHERE topic = ?
UNION
SELECT "user" AS subscriber, \'forum\' AS type, "key" FROM {interaction_forum_subscription_forum} WHERE forum = ?
ORDER BY type',
array($post->topicid, $post->forumid)
);
// A user may be subscribed via the forum or the specific topic. If they're subscribed to both, we want
// to focus on the topic subscription because it's more specific.
$sql = '
SELECT
subq2.subscriber,
(CASE WHEN subq2.topickey IS NOT NULL THEN subq2.topickey ELSE subq2.forumkey END) AS "key",
(CASE WHEN subq2.topickey IS NOT NULL THEN \'topic\' ELSE \'forum\' END) AS "type"
FROM (
SELECT subq1.subscriber, max(topickey) AS topickey, max(forumkey) AS forumkey
FROM (
SELECT "user" AS subscriber, "key" AS topickey, NULL AS forumkey FROM {interaction_forum_subscription_topic} WHERE topic = ?
UNION ALL
SELECT "user" AS subscriber, NULL AS topickey, "key" AS forumkey FROM {interaction_forum_subscription_forum} WHERE forum = ?
) subq1
GROUP BY subq1.subscriber
) subq2
INNER JOIN {usr} u ON subq2.subscriber = u.id
WHERE u.deleted = 0
';
$params = array($post->topicid, $post->forumid);
if ($cron) {
$sql .= ' AND subq2.subscriber > ? ';
$params[] = (int) $data->last_processed_userid;
$limitfrom = 0;
$limitnum = self::USERCHUNK_SIZE;
}
else {
$limitfrom = '';
$limitnum = '';
}
$sql .= ' ORDER BY subq2.subscriber';
$subscribers = get_records_sql_assoc($sql, $params, $limitfrom, $limitnum);
$this->users = $subscribers ? activity_get_users($this->get_id(), array_keys($subscribers)) : array();
$this->fromuser = $post->poster;
......
......@@ -503,6 +503,12 @@ abstract class ActivityType {
// because of the db trigger on notification_internal_activity.
}
/**
* Sound out notifications to $this->users.
* Note that, although this has batching properties built into it with USERCHUNK_SIZE,
* it's also recommended to update a bulk ActivityType's constructor to limit the total
* number of records pulled from the database.
*/
public function notify_users() {
safe_require('notification', 'internal');
$this->type = $this->get_id();
......@@ -526,9 +532,10 @@ abstract class ActivityType {
$num_processed_users++;
}
else {
return $last_processed_userid;
break;
}
}
return $last_processed_userid;
}
else {
while (!empty($this->users)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment