Last active
December 17, 2015 03:19
-
-
Save joshuaadickerson/5541980 to your computer and use it in GitHub Desktop.
Load all of the membergroups instead of loading them individually
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Load all of the membergroups | |
* | |
* @global array $smcFunc | |
* @global array $context | |
* @global array $modSettings | |
*/ | |
function loadMemberGroups($force = false) | |
{ | |
global $smcFunc, $context, $modSettings; | |
$context['membergroups'] = array(); | |
if ($force || (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($context['membergroups'] = cache_get_data('all-membergroups')) !== null)) | |
{ | |
$request = $smcFunc['db_query']('', ' | |
SELECT * | |
FROM {db_prefix}membergroups | |
ORDER BY group_name', | |
array() | |
); | |
while ($row = $smcFunc['db_fetch_assoc']($request)) | |
{ | |
$id = (int) $row['id_group']; | |
$context['membergroups'][$id] = $row; | |
$context['membergroups'][$id]['assignable'] = $context['membergroups'][$id]['min_posts'] == -1; | |
$context['membergroups'][$id]['is_post_group'] = $context['membergroups'][$id]['min_posts'] != -1; | |
} | |
$smcFunc['db_free_result']($request); | |
cache_put_data('all-membegroups', $context['membergroups'], 180); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also reduce the number of joins and columns in that function:
// Used by default
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
mem.birthdate, mem.member_ip, mem.member_ip2, mem.posts, mem.last_login,
mem.karma_good, mem.id_post_group, mem.karma_bad, mem.lngfile, mem.id_group, mem.time_offset, mem.show_online,
mem.is_activated, mem.warning, mem.usertitle';
$select_tables = '
LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)';