Skip to content
  • Hot
  • Top
  • New
0
vote

You have ... votes left in this category for this week!

Add delay and/or wait for space for search results while typing

MSB shared this feature

February 22, 2023

While typing in the search box, the ajax suggestion/search function gets fired a lot.
Own example:
Searching for a product by typing 2 words resulted in 22 requests to the following endpoint:
action=inlinesss&post_type=&searchstring=….
severely impacting the servers resources.

Possible suggestions for options:
– Add delay to await and evaluate if user stopped typing before searching
– Limit searches to A: When user stopped typing, and/or B: When a space is entered while typing (so we still get results while typing)

feature attachments:

3 Comments

  1. Dave H.
    February 22, 2023 @ 3:21 pm

    Agreed – I have an upgrade planned where I’m actually going to hold onto all the 2-character suggestion combinations in a front-end JSON object, so no DB calls will occur until 3 or more characters are entered.

    There already IS a delay, but maybe it’s too low (I think it’s 50ms at the moment) and I should definitely add an option to increase the delay and/or delay until the user hits space or enter.

    Reply

  2. Dave H.
    February 22, 2023 @ 3:25 pm

    In the meantime, you can probably speed up these queries quite a bit by adding the following advanced/beta/undocumented options to your wp-config.php – please test and let me know:

    if (isset($_REQUEST['fastajax']) && $_REQUEST['fastajax'] == 'true') {
    define('WP_USE_THEMES', false);
    }
    if (isset($_REQUEST['sss'])) {
    define('WP_USE_THEMES', false);
    }

    define( 'SSS_USE_FAST_SUGGESTIONS_AJAX', true ); // depending on your hosting, this may break the suggestions ajax callback

    define( 'SSS_FAST_VISIBILITY_CHECK', true);

    The above should go in your WP-CONFIG.php (not functions.php) and should go anywhere before the line which reads:


    /* That's all, stop editing! Happy publishing. */

    Reply

  3. P L.
    February 22, 2023 @ 4:19 pm

    Thank you for the fast response!

    Implemented your suggestion and that does seem to speed up the search (and consume less server resources) than before.

    But it still hits the DB “hard” with the large amount of requests it does while typing.
    For now I’ve disabled the ajax suggestions and will try again when the delay/space/enter options are implemented.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *