- Remove left join for query used to retrieve already assigned users and groups within permission panel - #20235

- also test the serialize/unserialize approach for cached roles

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8390 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2008-02-23 14:06:46 +00:00
parent 6accc46024
commit 2003152c8d
4 changed files with 65 additions and 52 deletions

View file

@ -125,7 +125,7 @@
<li>[Fix] Custom BBCode {EMAIL}-Token usage (Bug #21155)</li> <li>[Fix] Custom BBCode {EMAIL}-Token usage (Bug #21155)</li>
<li>[Fix] Do not rely on parameter returned by unlink() for verifying cache directory write permission (Bug #19565)</li> <li>[Fix] Do not rely on parameter returned by unlink() for verifying cache directory write permission (Bug #19565)</li>
<li>[Change] Use correct string for filesize (MiB instead of MB for example)</li> <li>[Change] Use correct string for filesize (MiB instead of MB for example)</li>
<li>[Change] Remove left join for query used to retrieve already assigned users and groups within permission panel (Bug #20235)</li>
</ul> </ul>
<a name="v30rc8"></a><h3>1.i. Changes since 3.0.RC8</h3> <a name="v30rc8"></a><h3>1.i. Changes since 3.0.RC8</h3>

View file

@ -124,7 +124,7 @@ class acp_permissions
$forum_id = array(); $forum_id = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$forum_id[] = $row['forum_id']; $forum_id[] = (int) $row['forum_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
@ -133,7 +133,7 @@ class acp_permissions
$forum_id = array(); $forum_id = array();
foreach (get_forum_branch($subforum_id, 'children') as $row) foreach (get_forum_branch($subforum_id, 'children') as $row)
{ {
$forum_id[] = $row['forum_id']; $forum_id[] = (int) $row['forum_id'];
} }
} }
@ -598,7 +598,7 @@ class acp_permissions
$ids = array(); $ids = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$ids[] = $row[$sql_id]; $ids[] = (int) $row[$sql_id];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
@ -1117,31 +1117,51 @@ class acp_permissions
global $db, $user; global $db, $user;
$sql_forum_id = ($permission_scope == 'global') ? 'AND a.forum_id = 0' : ((sizeof($forum_id)) ? 'AND ' . $db->sql_in_set('a.forum_id', $forum_id) : 'AND a.forum_id <> 0'); $sql_forum_id = ($permission_scope == 'global') ? 'AND a.forum_id = 0' : ((sizeof($forum_id)) ? 'AND ' . $db->sql_in_set('a.forum_id', $forum_id) : 'AND a.forum_id <> 0');
$sql_permission_option = ' AND o.auth_option ' . $db->sql_like_expression($permission_type . $db->any_char);
$sql = $db->sql_build_query('SELECT_DISTINCT', array( // Permission options are only able to be a permission set... therefore we will pre-fetch the possible options and also the possible roles
'SELECT' => 'u.username, u.username_clean, u.user_regdate, u.user_id', $option_ids = $role_ids = array();
'FROM' => array( $sql = 'SELECT auth_option_id
USERS_TABLE => 'u', FROM ' . ACL_OPTIONS_TABLE . '
ACL_OPTIONS_TABLE => 'o', WHERE auth_option ' . $db->sql_like_expression($permission_type . $db->any_char);
ACL_USERS_TABLE => 'a' $result = $db->sql_query($sql);
),
'LEFT_JOIN' => array( while ($row = $db->sql_fetchrow($result))
array( {
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), $option_ids[] = (int) $row['auth_option_id'];
'ON' => 'a.auth_role_id = r.role_id' }
) $db->sql_freeresult($result);
),
'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id) if (sizeof($option_ids))
$sql_permission_option {
$sql = 'SELECT DISTINCT role_id
FROM ' . ACL_ROLES_DATA_TABLE . '
WHERE ' . $db->sql_in_set('auth_option_id', $option_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$role_ids[] = (int) $row['role_id'];
}
$db->sql_freeresult($result);
}
if (sizeof($option_ids) && sizeof($role_ids))
{
$sql_where = 'AND (' . $db->sql_in_set('a.auth_option_id', $option_ids) . ' OR ' . $db->sql_in_set('a.auth_role_id', $role_ids) . ')';
}
else
{
$sql_where = 'AND ' . $db->sql_in_set('a.auth_option_id', $option_ids);
}
// Not ideal, due to the filesort, non-use of indexes, etc.
$sql = 'SELECT DISTINCT u.user_id, u.username
FROM ' . USERS_TABLE . ' u, ' . ACL_USERS_TABLE . " a
WHERE u.user_id = a.user_id
$sql_forum_id $sql_forum_id
AND u.user_id = a.user_id", $sql_where
ORDER BY u.username_clean, u.user_regdate ASC";
'ORDER_BY' => 'u.username_clean, u.user_regdate ASC'
));
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$s_defined_user_options = ''; $s_defined_user_options = '';
@ -1153,29 +1173,12 @@ class acp_permissions
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$sql = $db->sql_build_query('SELECT_DISTINCT', array( $sql = 'SELECT DISTINCT g.group_type, g.group_name, g.group_id
'SELECT' => 'g.group_type, g.group_name, g.group_id', FROM ' . GROUPS_TABLE . ' g, ' . ACL_GROUPS_TABLE . " a
WHERE g.group_id = a.group_id
'FROM' => array(
GROUPS_TABLE => 'g',
ACL_OPTIONS_TABLE => 'o',
ACL_GROUPS_TABLE => 'a'
),
'LEFT_JOIN' => array(
array(
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
'ON' => 'a.auth_role_id = r.role_id'
)
),
'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
$sql_permission_option
$sql_forum_id $sql_forum_id
AND g.group_id = a.group_id", $sql_where
ORDER BY g.group_type DESC, g.group_name ASC";
'ORDER_BY' => 'g.group_type DESC, g.group_name ASC'
));
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$s_defined_group_options = ''; $s_defined_group_options = '';

View file

@ -113,7 +113,7 @@ class auth_admin extends auth
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$forum_ids[] = $row['forum_id']; $forum_ids[] = (int) $row['forum_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }

View file

@ -453,10 +453,15 @@ class auth
$this->role_cache = array(); $this->role_cache = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$this->role_cache[$row['role_id']][$row['auth_option_id']] = (bool) $row['auth_setting']; $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
foreach ($this->role_cache as $role_id => $role_options)
{
$this->role_cache[$role_id] = serialize($role_options);
}
$cache->put('_role_cache', $this->role_cache); $cache->put('_role_cache', $this->role_cache);
// Now empty user permissions // Now empty user permissions
@ -747,10 +752,15 @@ class auth
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$this->role_cache[$row['role_id']][$row['auth_option_id']] = (bool) $row['auth_setting']; $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
foreach ($this->role_cache as $role_id => $role_options)
{
$this->role_cache[$role_id] = serialize($role_options);
}
$cache->put('_role_cache', $this->role_cache); $cache->put('_role_cache', $this->role_cache);
} }
@ -767,7 +777,7 @@ class auth
// If a role is assigned, assign all options included within this role. Else, only set this one option. // If a role is assigned, assign all options included within this role. Else, only set this one option.
if ($row['auth_role_id']) if ($row['auth_role_id'])
{ {
$hold_ary[$row['forum_id']] = (empty($hold_ary[$row['forum_id']])) ? $this->role_cache[$row['auth_role_id']] : $hold_ary[$row['forum_id']] + $this->role_cache[$row['auth_role_id']]; $hold_ary[$row['forum_id']] = (empty($hold_ary[$row['forum_id']])) ? unserialize($this->role_cache[$row['auth_role_id']]) : $hold_ary[$row['forum_id']] + unserialize($this->role_cache[$row['auth_role_id']]);
} }
else else
{ {
@ -792,7 +802,7 @@ class auth
} }
else else
{ {
foreach ($this->role_cache[$row['auth_role_id']] as $option_id => $setting) foreach (unserialize($this->role_cache[$row['auth_role_id']]) as $option_id => $setting)
{ {
$this->_set_group_hold_ary($hold_ary[$row['forum_id']], $option_id, $setting); $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $option_id, $setting);
} }