Skip to content
Browse files

Performance fix for moderator list (exclude inactive) - DB

  • Loading branch information...
1 parent 4588cb2 commit 51b6ab2d8973b29c9a98329407769d1a9b28a3d6 @GroM GroM committed
Showing with 24 additions and 8 deletions.
  1. +16 −8 include/db/PhorumDB.php
  2. +8 −0 include/db/upgrade/mysql-patches/2012030800.php
View
24 include/db/PhorumDB.php
@@ -3356,13 +3356,21 @@ public function user_get_moderators($forum_id, $exclude_admin=FALSE, $for_email=
settype($exclude_admin, 'bool');
settype($for_email, 'bool');
- // Exclude admins from the list, if requested.
- $or_where_admin = $exclude_admin ? '' : 'OR u.admin=1';
-
// If we are gathering email addresses for mailing the moderators,
// then honour the moderation_email setting for the user.
$where_moderation_mail = $for_email ? 'AND u.moderation_email = 1' : '';
+ // Exclude admins from the list, if requested.
+ $admin = $exclude_admin ? '' :
+ "SELECT DISTINCT user.user_id AS user_id,
+ user.email AS email
+ FROM {$this->user_table} AS u
+ WHERE u.active=1 AND u.admin=1
+ $where_moderation_mail
+ UNION
+ ";
+
+
$moderators = array();
// Look up moderators which are configured through user permissions.
@@ -3370,12 +3378,12 @@ public function user_get_moderators($forum_id, $exclude_admin=FALSE, $for_email=
DB_RETURN_ROWS,
"SELECT DISTINCT u.user_id AS user_id,
u.email AS email
- FROM {$this->user_table} AS u
- LEFT JOIN {$this->user_permissions_table} AS perm
+ FROM {$this->user_permissions_table} AS perm
+ INNER JOIN {$this->user_table} AS u
ON perm.user_id = u.user_id
- WHERE ((perm.permission>=".PHORUM_USER_ALLOW_MODERATE_MESSAGES." AND
- (perm.permission & ".PHORUM_USER_ALLOW_MODERATE_MESSAGES.">0)
- AND perm.forum_id = $forum_id) $or_where_admin)
+ WHERE perm.forum_id = $forum_id AND u.active = 1
+ (perm.permission>=".PHORUM_USER_ALLOW_MODERATE_MESSAGES." AND
+ (perm.permission & ".PHORUM_USER_ALLOW_MODERATE_MESSAGES.">0)
$where_moderation_mail"
);
View
8 include/db/upgrade/mysql-patches/2012030800.php
@@ -0,0 +1,8 @@
+<?php
+
+$upgrade_queries[]=
+ "ALTER TABLE {$PHORUM['user_table']}
+ DROP INDEX active,
+ ADD INDEX active(active, admin);";
+
+?>

0 comments on commit 51b6ab2

Please sign in to comment.
Something went wrong with that request. Please try again.