[i18n] locale-based sort, new suggestion

persian-horde@metanetworking.com persian-horde at metanetworking.com
Wed May 11 15:21:27 PDT 2005


> Indeed. And this function does at least one more loop through the
> *entire* contents of the mailbox than it has to, and makes no attempt
> whatsover to only run for locales where it's needed - thus vastly
> decreasing performance for many users. If these problems are address we
>  can talk further.
>

Hello,

Well we optimized the imap_locale_sort function by omitting two loops in
this function, resulting in better performance:

function imap_locale_sort($stream,$criteria,$reverse,$locale,$options)
{
        if ($criteria!=SORTSUBJECT)
                return (imap_sort($stream,$criteria,$reverse,$options));

       $sortresult = array();

        $MC=imap_check($stream);
        $MN=$MC->Nmsgs;

        $overview = imap_fetch_overview($stream,"1:$MN",0);
        usort ($overview, create_function('$a,$b','setlocale
(LC_ALL,$locale);return strcoll(imap_utf8($a->subject),imap_utf8($b-
>subject));'));

        $sortresult = array_map(create_function('$a','return $a-
>uid;'),$overview);

        if ($reverse)
                $sortresult = array_reverse($sortresult);

        return $sortresult;
}

> whatsover to only run for locales where it's needed

We can use from $nls['localesort'] in horde nls.php file which specifies
the locales which need imap_locale_sort, and in the code we use
imap_locale_sort for this locales only:

config/nls.php:
$nls['localesort']['fa_IR'] = true;

imp/lib/Mailbox.php:
if ($GLOBALS['nls']['localesort'][$GLOBALS['language']])
	$sorted = @call_user_func_array('imap_locale_sort', $cmd);
else
	$sorted = @call_user_func_array('imap_sort', $cmd);


We can also avoid the above "if ", if we could somehow override the
imap_sort function in specific locales. For this to work we should have a
similar argument list for both imap_sort and imap_locale_sort, which can
be done by omitting $locale from argument list and filling its value
inside the imap_locale_sort:

function imap_locale_sort($stream,$criteria,$reverse,$options)
{
$locale = $GLOBALS['language'];
.
.
.

We hope that we could address the performance issues noted by chuck.
Till now more than 5 other translators say that the imp sort/search
functions does not work correctly in their locales. Hope that new changes
would make horde/imp more complete.

Thanks and Regards,
Persian-Horde Team.










More information about the i18n mailing list