So when getting around 2000 MySQL rows in JSON format it takes around 10 seconds to return the data upon my AJAX call.
9 seconds of waiting time (TTFB)
1 second to download content...
Does anyone know how to speed this up?
Currently I'm getting all results of the MySQL search (without any LIMIT
), and I created pages by slicing the JSON data.
I guess one way to reduce the payload is to send the page number through the AJAX call and LIMIT
the MySQL search, but is there really no other way?
Down below is my original MySQL search query.
It's complex because I have a single search box that searches for the search keyword in my Database in several fields like the title, the categories, etc...
Everywhere it says LIKE '%%'
is where the search term goes.
However on a selection for the category it filters the MySQL search in a different place: see LIKE '%health-and-beauty%'
and the LIKE '%%'
stays empty.
SELECT wpp.ID, post_title, wp_terms.name AS category, wp_terms.slug AS slug, supplier_company,
GROUP_CONCAT(wp_terms.slug SEPARATOR ', ') AS allslug,
GROUP_CONCAT(wp_terms.name SEPARATOR ', ') AS allcatname
FROM wp_posts AS wpp
LEFT JOIN wp_term_relationships ON wpp.ID = object_id
LEFT JOIN wp_terms ON term_taxonomy_id = wp_terms.term_id
LEFT JOIN wp_teleapo_supplier AS s ON wpp.post_author = s.ID
/* BASIC SEARCH on normal fields */
WHERE post_type = 'post'
GROUP BY wpp.ID
/* SEARCH on CONCAT FIELDS*/
HAVING
(post_title LIKE '%%'
OR allcatname LIKE '%%'
OR allslug LIKE '%%'
OR supplier_company LIKE '%%')
AND (allslug LIKE '%health-and-beauty%'
) AND (allslug LIKE '%%'
) AND
/* ADD EXTRA SEARCH TAGS: */
/* Language tag */
allslug LIKE '%english%'
/* ..... tag */
/* AND allslug LIKE '%......... %' */
ORDER BY post_date DESC