Hi, after troubleshooting our installation (wordpress 6.1,
TranslatePress – Multilingual 2.4.2), i found out that gettext mysql tables are not-optimal and some slow queries, resolving these issues in source code and database manually solved our issues (slow rendering of each page)
So for anyone, and maybe developers of translate-press even, here’s what i did:
(1) missing indexes
eg. wp433_trp_gettext_en_gb missing index/key on columns “domain”, “original_id” (and maybe “status”)
-> manually via phpmyadmin, in each gettext table structure, add “index” to at least those 2 columns
original create table query
CREATE TABLE wp433_trp_gettext_en_gb (
id bigint(20) NOT NULL AUTO_INCREMENT,
original longtext NOT NULL,
translated longtext DEFAULT NULL,
domain longtext DEFAULT NULL,
status int(20) DEFAULT NULL,
original_id bigint(20) DEFAULT NULL,
plural_form int(20) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id),
KEY index_name (original(100)),
KEY domain (domain(768)),
KEY status (status),
KEY original_id (original_id),
FULLTEXT KEY original_fulltext (original)
) ENGINE=InnoDB AUTO_INCREMENT=24464 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`
updated create table
CREATE TABLEwp433_trp_gettext_en_gb` (
id bigint(20) NOT NULL AUTO_INCREMENT,
original longtext NOT NULL,
translated longtext DEFAULT NULL,
domain longtext DEFAULT NULL,
status int(20) DEFAULT NULL,
original_id bigint(20) DEFAULT NULL,
plural_form int(20) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id),
KEY index_name (original(100)),
// => these keys are added
KEY domain (domain(768)),
KEY status (status),
KEY original_id (original_id),
// => end of modifications
FULLTEXT KEY original_fulltext (original)
) ENGINE=InnoDB AUTO_INCREMENT=24464 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`
(2) slow query involving union/distinct/collate
method: translatepress-multilingual/includes/string-translation/class-string-translation.php::TRP_String_Translation::get_gettext_domains
default constructed query looks like this:
SELECT domain FROM wp433_trp_gettext_en_gb UNION SELECT domain FROM wp433_trp_gettext_en_us UNION SELECT domain FROM wp433_trp_gettext_cs_cz ORDER BY domain ASC;
this uses UNION(DISTINCT) and ORDER and takes about 1.7 seconds on MariaDB 10.5.18
-> manually updated function to use “UNION ALL” and not add “order by”, this took the query down to 0.075 second