Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: th23 on October 11, 2009, 08:37:05 AM

Title: Speed up autocomplete for addresses
Post by: th23 on October 11, 2009, 08:37:05 AM
Hi together,

first of all many thanks to the developers for this really nice piece of software :)

But one thing that struck me from the beginning was, how slow the autocomplete feature for mail addresses in the compose window works - e.g. compared to all loved GMail. Looking a little deeper into it, I am surprised this seems to be done via a server request after each typed letter :o

How about "preloading" the list of all possible addressbooks (autocomplete enabled) for the user when he opens the compose window and do all the selection/autocomplete via a solely clientbased javascript?

I came across this (http://wick.sourceforge.net/wick_sample/) oviously older, but rather quit and easy working solution!?

th23
Title: Speed up autocomplete for addresses
Post by: SKaero on October 11, 2009, 09:23:28 AM
It can be a problem, nice script you linked to but I don't think that would work for big address books. There are some ticket on this like: #1485675 (addressbook useless when having big number of addresses stored) ? Roundcube Webmail (http://trac.roundcube.net/ticket/1485675)
Title: Speed up autocomplete for addresses
Post by: th23 on October 11, 2009, 09:43:00 AM
Quote from: skaero;22051
...but I don't think that would work for big address books.

I will check the tickets - thanks for the hint, didn't do so far.

But on the size of the address books: The linked script (not my work) provides a test page that works on a JavaScript array of about 5.000 entries without any delay or anything like that...

---

Okay, I just found this ticket (http://trac.roundcube.net/ticket/1485531) in the tracker that seems to indicate there was a solely client side solution before...but why removing it completely without the suggested switch, that would have made life a lot faster for non-LDAP users?
Title: Speed up autocomplete for addresses
Post by: th23 on October 12, 2009, 08:27:34 AM
Okay, I just reverted some of the changes done in order to close one of those tickets and reenabled the client side searching...works fast and reliable with slow connections as well :)

I haven't tested it with huge addressbooks and/or LDAP (support for LDAP currently NOT implemented, but according to the older source it shouldn't be too tricky to add, except for the "searchable", but "not browsable" access)
Title: Speed up autocomplete for addresses
Post by: SKaero on October 12, 2009, 09:02:29 AM
Can you post the changes you did, it would be nice to test it out.
Title: Speed up autocomplete for addresses
Post by: th23 on October 12, 2009, 09:33:37 AM
Sure, actually it's only changes in two files - I didn't manage to utilize the new hook system as their seem to be no appropriate hooks for this task:

program/steps/mail/compose.inc

Find:

$OUTPUT->send('compose');


Add before:

// th23 start - client autocomplete
$th23_client_autocomplete_array = array();

// get autocomplete addressbooks for user
$th23_client_autocomplete_book_list = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
foreach ($th23_client_autocomplete_book_list as $th23_client_autocomplete_book_id)
{
$th23_client_autocomplete_book = $RCMAIL->get_address_book($th23_client_autocomplete_book_id);
$th23_client_autocomplete_book->set_pagesize(1000);

// get and format contacts of these addressbooks for JS array
if ($th23_client_autocomplete_contacts = $th23_client_autocomplete_book->list_records())
{
while ($th23_client_autocomplete_contact = $th23_client_autocomplete_contacts->iterate())
{
if ($th23_client_autocomplete_contact['email'] && !empty($th23_client_autocomplete_contact['email']))
{
$th23_client_autocomplete_array[] = format_email_recipient($th23_client_autocomplete_contact['email'], $th23_client_autocomplete_contact['name']);
}
}
}
}

// TODO: get additional LDAP autocomplete contacts

// make JS contact array available in compose screen
$OUTPUT->set_env('th23_client_autocomplete_contacts', $th23_client_autocomplete_array);
// th23 end - client autocomplete


program/js/app.js(.src)

Find:

    this.display_message(this.get_label('searching'), 'loading', true);
    this.http_post('autocomplete', '_search='+urlencode(q));


Add before:

// th23 start - client autocomplete

// check for th23_client_autocomplete_contacts
if (typeof(this.env.th23_client_autocomplete_contacts)!='object' || !this.env.th23_client_autocomplete_contacts.length)
{
return true;
}
   
// search the th23_client_autocomplete_contacts
var th23_client_autocomplete_matches = new Array();
var th23_client_autocomplete_matches_ids = new Array();
var c=0;

for (var i=0; i {
if (this.env.th23_client_autocomplete_contacts[i].toLowerCase().indexOf(q)>=0)
{
th23_client_autocomplete_matches[c] = this.env.th23_client_autocomplete_contacts[i];
th23_client_autocomplete_matches_ids[c++] = i;
if (c==10)
{
break;
}
}
}

// show the results
this.env.contacts = th23_client_autocomplete_matches;
this.ksearch_display_results(this.env.contacts);

/*
// th23 end - client autocomplete


Add after:

// th23 start - client autocomplete
*/
// th23 end - client autocomplete
Title: Speed up autocomplete for addresses
Post by: SKaero on October 12, 2009, 09:42:41 AM
Thanks, it would be great if it got LDAP support ;D. Moved to Plug-Ins.