r107433 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107432‎ | r107433 | r107434 >
Date:21:40, 27 December 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Yay, more memcaching
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -199,6 +199,10 @@
200200
201201 /**
202202 * Wrapper for ldap_add
 203+ * @param $ldapconn
 204+ * @param $dn
 205+ * @param $entry
 206+ * @return bool
203207 */
204208 public static function ldap_add( $ldapconn, $dn, $entry ) {
205209 wfSuppressWarnings();
@@ -1366,16 +1370,19 @@
13671371 * @return array|null
13681372 */
13691373 function getUserInfoStateless( $userdn ) {
1370 - // Don't fetch the same data more than once
1371 - // TODO: use memcached here
 1374+ global $wgMemc;
 1375+ $key = wfMemcKey( 'ldapauthentication', 'userdn', $userdn );
13721376
1373 - $entry = LdapAuthenticationPlugin::ldap_read( $this->ldapconn, $userdn, "objectclass=*", array( '*', 'memberof' ) );
1374 - $userInfo = LdapAuthenticationPlugin::ldap_get_entries( $this->ldapconn, $entry );
1375 - if ( $userInfo["count"] < 1 ) {
1376 - return null;
1377 - } else {
1378 - return $userInfo;
 1377+ $userInfo = $wgMemc->get( $key );
 1378+ if ( !is_array( $userInfo ) ) {
 1379+ $entry = LdapAuthenticationPlugin::ldap_read( $this->ldapconn, $userdn, "objectclass=*", array( '*', 'memberof' ) );
 1380+ $userInfo = LdapAuthenticationPlugin::ldap_get_entries( $this->ldapconn, $entry );
 1381+ if ( $userInfo["count"] < 1 ) {
 1382+ return null;
 1383+ }
 1384+ $wgMemc->set( $key, $userInfo );
13791385 }
 1386+ return $userInfo;
13801387 }
13811388
13821389 /**
@@ -1477,6 +1484,7 @@
14781485
14791486 /**
14801487 * Function to get the user's groups.
 1488+ * @param string $username
14811489 */
14821490 private function getGroups( $username ) {
14831491 $this->printDebug( "Entering getGroups", NONSENSITIVE );
@@ -1550,12 +1558,12 @@
15511559 * $searchedgroups is used for tail recursion and shouldn't be provided
15521560 * when called externally.
15531561 *
1554 - * @param string $userDN
 1562+ * @param $groups
15551563 * @param array $searchedgroups
15561564 * @return bool
15571565 * @access private
15581566 */
1559 - function searchNestedGroups( $groups, $searchedgroups = array( "dn" => Array(), "short" => Array() ) ) {
 1567+ function searchNestedGroups( $groups, $searchedgroups = array( "dn" => array(), "short" => array() ) ) {
15601568 $this->printDebug( "Entering searchNestedGroups", NONSENSITIVE );
15611569
15621570 // base case, no more groups left to check

Follow-up revisions

RevisionCommit summaryAuthorDate
r107435A non 0 cache expiry time is probably a good idea...reedy21:43, 27 December 2011
r107436Follow up to r107433. Delete userinfo key when modifying user.laner21:53, 27 December 2011

Comments

#Comment by Ryan lane (talk | contribs)   21:47, 27 December 2011

I had avoided adding memcache support here just yet, as it's possible that other parts of the code may update the user and what's in memcache would then be invalid. We need to identify parts of the code that update the user's entry, and cause them to invalidate the key.

Status & tagging log