Thomas Bruederli
2013-02-14 807c3d0d9745e850d08ceb2a1d6c018f8b791706
Optimmize memory usage by only fetching the necessary attributes used for contacts listing
3 files modified
22 ■■■■ changed files
program/lib/Roundcube/rcube_ldap.php 15 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_ldap_generic.php 3 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_ldap_result.php 4 ●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_ldap.php
@@ -193,8 +193,14 @@
        $rcube = rcube::get_instance();
        $this->cache = $rcube->get_cache('LDAP.' . asciiwords($this->prop['name']), 'db', 600);
        // initialize ldap wrapper object
        // determine which attributes to fetch
        $this->prop['attributes'] = array_merge(array_values($this->fieldmap), $fetch_attributes);
        $this->prop['list_attributes'] = $fetch_attributes;
        foreach ($rcube->config->get('contactlist_fields') as $col) {
            $this->prop['list_attributes'] = array_merge($this->prop['list_attributes'], $this->_map_field($col));
        }
        // initialize ldap wrapper object
        $this->ldap = new rcube_ldap_generic($this->prop, true);
        $this->ldap->set_cache($this->cache);
@@ -567,7 +573,7 @@
            return $group_members;
        // read these attributes for all members
        $attrib = $count ? array('dn','objectClass') : $this->prop['attributes'];
        $attrib = $count ? array('dn','objectClass') : $this->prop['list_attributes'];
        $attrib[] = 'member';
        $attrib[] = 'uniqueMember';
        $attrib[] = 'memberURL';
@@ -605,15 +611,14 @@
    {
        $group_members = array();
        for ($i=0; $i < $entry['memberurl']['count']; $i++)
        {
        for ($i=0; $i < $entry['memberurl']['count']; $i++) {
            // extract components from url
            if (!preg_match('!ldap:///([^\?]+)\?\?(\w+)\?(.*)$!', $entry['memberurl'][$i], $m))
                continue;
            // add search filter if any
            $filter = $this->filter ? '(&(' . $m[3] . ')(' . $this->filter . '))' : $m[3];
            $attrs = $count ? array('dn','objectClass') : $this->prop['attributes'];
            $attrs = $count ? array('dn','objectClass') : $this->prop['list_attributes'];
            if ($result = $this->ldap->search($m[1], $filter, $m[2], $attrs, $this->group_data)) {
                $entries = $result->entries();
                for ($j = 0; $j < $entries['count']; $j++) {
program/lib/Roundcube/rcube_ldap_generic.php
@@ -412,6 +412,9 @@
                        $this->_debug("S: ".($errmsg ? $errmsg : ldap_error($this->conn)));
                    }
                }
                else if ($this->debug) {
                    $this->_debug("S: ".ldap_count_entries($this->conn, $ldap_result)." record(s) found");
                }
                $this->result = new rcube_ldap_result($this->conn, $ldap_result, $base_dn, $filter, $vlv_count);
program/lib/Roundcube/rcube_ldap_result.php
@@ -100,7 +100,9 @@
    function current()
    {
        return ldap_get_attributes($this->conn, $this->current);
        $attrib = ldap_get_attributes($this->conn, $this->current);
        $attrib['dn'] = ldap_get_dn($this->conn, $this->current);
        return $attrib;
    }
    function key()