diff --git a/includes/mail.inc b/includes/mail.inc index 7dd2860..71ea19c 100644 --- a/includes/mail.inc +++ b/includes/mail.inc @@ -285,7 +285,7 @@ function project_issue_mail_notify($nid) { // 'Own' level using the list of users attached to the issue. if (!empty($own_issues_uids)) { $placeholders = implode(',', array_fill(0, count($own_issues_uids), '%d')); - $filter_array[] = "(pi.uid IN ($placeholders) AND pi.level = " . PROJECT_ISSUE_SUBSCRIPTIONS_FLAGGED . ")"; + $filter_array[] = "(pi.level = " . PROJECT_ISSUE_SUBSCRIPTIONS_FLAGGED . " AND u.uid IN ($placeholders))"; $args = array_merge($args, $own_issues_uids); } $filter = implode(" OR ", $filter_array); diff --git a/project_issue.install b/project_issue.install index f4e8fa1..3e4ad08 100644 --- a/project_issue.install +++ b/project_issue.install @@ -303,7 +303,7 @@ function project_issue_schema() { ), 'primary key' => array('uid'), 'indexes' => array( - 'uid_level' => array('uid', 'level'), + 'level' => array('level'), ), ); @@ -335,7 +335,7 @@ function project_issue_schema() { ), 'primary key' => array('uid', 'nid'), 'indexes' => array( - 'project_subscriptions_nid_uid_level' => array('nid', 'uid', 'level'), + 'nid_level' => array('nid', 'level'), ), ); @@ -654,9 +654,18 @@ function project_issue_update_6006() { } /** + * Ensure that existing project subscriptions are clean. + */ +function project_issue_update_6007() { + $ret = array(); + $ret[] = update_sql("DELETE FROM {project_subscriptions} WHERE level = 0"); + return $ret; +} + +/** * Clean up duplicates in {project_subscriptions}. */ -function project_issue_update_6007(&$sandbox) { +function project_issue_update_6008(&$sandbox) { $ret = array(); if (!isset($sandbox['total'])) { @@ -693,9 +702,10 @@ function project_issue_update_6007(&$sandbox) { } /** - * Revamp project issue subscriptions for Flag integration. + * Move subscriptions into the project_issue namespace, and split into + * user-level and project-level. */ -function project_issue_update_6008() { +function project_issue_update_6009() { $ret = array(); // Delete obsolete 'project_issue_global_subscribe_page' variable. @@ -726,7 +736,7 @@ function project_issue_update_6008() { ), 'primary key' => array('uid'), 'indexes' => array( - 'uid_level' => array('uid', 'level'), + 'level' => array('level'), ), )); @@ -734,23 +744,37 @@ function project_issue_update_6008() { } /** - * Ensure that existing project subscriptions are clean. + * Add primary key to {project_issue_subscriptions_project}. + * + * WARNING: This update can take a *very* long time (potentially hours) if + * there are a high number of rows in the table. The test table had 2.34 + * million rows, and the query took over three hours on reasonable hardware. */ -function project_issue_update_6009() { +function project_issue_update_6010() { $ret = array(); - $ret[] = update_sql("DELETE FROM {project_issue_subscriptions_project} WHERE level = 0"); + db_add_primary_key($ret, 'project_issue_subscriptions_project', array('uid', 'nid')); return $ret; } /** - * Add primary key to {project_issue_subscriptions_project}. + * Add nid_level key to {project_issue_subscriptions_project}. * * WARNING: This update can take a *very* long time (potentially hours) if - * there are a high number of rows in the table. The test table had 2.34 - * million rows, and the query took over three hours on reasonable hardware. + * there are a high number of rows in the table. */ -function project_issue_update_6010() { +function project_issue_update_6011() { $ret = array(); - db_add_primary_key($ret, 'project_issue_subscriptions_project', array('uid', 'nid')); + db_add_index($ret, 'project_issue_subscriptions_project', 'nid_level', array('nid', 'level')); return $ret; } + +/** + * Drop unneccessary indexes from {project_issue_subscriptions_project}. + */ +function project_issue_update_6012() { + $ret = array(); + db_drop_index($ret, 'project_issue_subscriptions_project', 'uid'); + db_drop_index($ret, 'project_issue_subscriptions_project', 'project_subscriptions_nid_uid_level'); + return $ret; +} + diff --git a/project_issue.module b/project_issue.module index 06f552d..a261bd6 100644 --- a/project_issue.module +++ b/project_issue.module @@ -949,28 +949,19 @@ function project_issue_subscriptions_user_settings_load($account) { * - PROJECT_ISSUE_SUBSCRIPTIONS_NONE * - PROJECT_ISSUE_SUBSCRIPTIONS_FLAGGED * - PROJECT_ISSUE_SUBSCRIPTIONS_ALL - * When passing PROJECT_ISSUE_SUBSCRIPTIONS_NONE the user's per-user - * subscription setting is deleted. * * @see project_issue_subscriptions_user_settings_load() */ function project_issue_subscriptions_user_settings_save($account) { $level = $account->project_issue_subscriptions['level']; - if ($level > PROJECT_ISSUE_SUBSCRIPTIONS_NONE) { - db_query("UPDATE {project_issue_subscriptions_user} SET level = %d WHERE uid = %d", array( - $level, - $account->uid, - )); - if (!db_affected_rows()) { - db_query("INSERT INTO {project_issue_subscriptions_user} (uid, level) VALUES (%d, %d)", array( - $account->uid, - $level, - )); - } - } - else { - db_query("DELETE FROM {project_issue_subscriptions_user} WHERE uid = %d", array( + db_query("UPDATE {project_issue_subscriptions_user} SET level = %d WHERE uid = %d", array( + $level, + $account->uid, + )); + if (!db_affected_rows()) { + db_query("INSERT INTO {project_issue_subscriptions_user} (uid, level) VALUES (%d, %d)", array( $account->uid, + $level, )); } }