When starting to type a node id or issue title in the Issue relations field on an issue, autocomplete tries to be helpful and provide autocomplete suggestions for what the user has typed. Unfortunately, due to the very large number of (issue) nodes on drupal.org this means that until the user has typed a handful of characters, the match will return a result set that exceeds PHP's memory_limit in size. That means the autocomplete fails with an AJAX error and the background process that runs the (expensive, huge) query gets killed:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: https://drupal.org/entityreference/autocomplete/single/field_issue_parent/node/project_issue/NULL
StatusText: OK
ResponseText: Fatal error: Allowed memory size of 419430040 bytes exhausted (tried to allocate 77 bytes) in /var/www/drupal.org/htdocs/sites/all/modules/project_issue/plugins/entityreference_selection/ProjectIssue_SelectionHandler_Issues.class.php on line 123

This can't be good for d.o performance. Even if the result set fits in memory, it quite possibly returns (tens of?) thousands of nid|node rows that then need to get rendered in the browser... and it'll be making the MySQL server query cache cry.

To make this less of an issue, I suggest a few tweaks to the autocomplete handler:

  • Do not perform a title query until the user has typed at least three characters, or possibly even a few more.
  • Add a limit clause to the query so the result set can never be gigantic.
  • Order the result set by relevance or modification date. (I expect we have no relevance field, but issue status maybe? Closed filters to bottom? Length of matched title?)

Apropos of nothing, the query builder isn't using db_like() and for minimal speed gain its substr() call can be replaced with strpos(), which is 50% faster at checking the first character of a string, it seems ;-)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cafuego’s picture

Status: Active » Needs review
FileSize
2.77 KB
drumm’s picture

Status: Needs review » Needs work

Committed, except the last chunk, which has at least 2 syntax errors.

See http://drupal.org/node/1018084 for testing on Drupal.org dev sites.

kattekrab’s picture

Thanks @cafuego

Thanks @drumm

:)

cafuego’s picture

Whoops, those parse errors were rather untidy... fixed in this patch (which applies on top of the changes you've applied already).

However, I note that autocomplete seems to not return anything at all currently, which implies that the generated query has a problem. Mind you, that at least doesn't currently cause E_NOMEM errors ;-)

cafuego’s picture

Status: Needs work » Needs review

... and I'll do the wwwdev key thing a bit later today. Thanks drumm!

drumm’s picture

I went ahead added your keys to devwww, cafuego is the username. You can jump into the changerecords-drupal.redesign.devdrupal.org site. (xjm is working on a different section of the site, so you shouldn't get in each other's way unless you are causing sitewide WSODs. I expect this issue may be resolved faster.)

Please update this when it has been tested.

cafuego’s picture

Thanks drumm. Attached patch works on devwww.

I wonder if it's worthwhile overriding the core autocomplete js library and set a configurable minimum string length (via Drupal.behaviours) before autocomplete even runs its callback handler, which would then help with this particular issue on all autocomplete fields on d.o.

cafuego’s picture

I just added https://drupal.org/project/autocomplete_limit as a generic module to stop autocomplete from doing ajax callbacks on strings under a given length.

drumm’s picture

Status: Needs review » Fixed

Committed.

https://drupal.org/project/autocomplete_limit looks like it might be better done as a core patch. If it won't get into D7 core, and there is a 1.0 release, we can add it as a recommended module in project_issue.info and deploy on Drupal.org..

cafuego’s picture

It looks as if a version of this is in Drupal 8 already; I'll investigate and try and roll a D7 version and see what people think. If it's unlikely to get in, I'll push a 7.x-1.0 of the module - that's easy :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cafuego’s picture

Status: Closed (fixed) » Active

Since it's illegal to fix D7 (#2196543: Autocomplete minimum length), I suppose I'll roll a stable version of the contrib module.