Description
Description
Today I noticed my GraphQL queries taking ages (minimum of 1 second). Sending the same query again only takes about 100 ms because of caching. Changing the query or variables would take 1+ second again.
Did some digging in the Yii Debugger and noticed 3671 events were fired, mostly defineBehaviors, craft\events\DefineBehaviorsEvent, craft\models\EntryType
and init yii\base\Event craft\models\EntryType
. However so far I have only created 15 entrytypes.
With this I also noticed more MySQL queries than I would reasonably expect.
I compared this behaviour with a website in production. Running running 3.4.27 its also making makes 4271 events.
Hopefully some improvements can be made making GraphQL more lightweight! I'm not too sure what's happening underneath the hood but if I were to guess than it is probably rebuilding the entire GraphQL schema on every single new call? Just before the thousands of repeated events, RegisterGqlTypesEvent
is triggered.
Steps to reproduce
- Send a really simple GraphQL call to this simple Single, both GraphiQL explorer as external API calls give the same slow result.
{
entry(section: "homepage") {
id
title
slug
}
}
This MySQL query is being called 60 times total, with every layoutId was being called 3 times.
SELECT `fields`.`id`, `fields`.`dateCreated`, `fields`.`dateUpdated`, `fields`.`groupId`, `fields`.`name`, `fields`.`handle`, `fields`.`context`, `fields`.`instructions`, `fields`.`translationMethod`, `fields`.`translationKeyFormat`, `fields`.`type`, `fields`.`settings`, `fields`.`uid`, `fields`.`searchable`, `flf`.`layoutId`, `flf`.`tabId`, `flf`.`required`, `flf`.`sortOrder` FROM `fields` `fields` INNER JOIN `fieldlayoutfields` `flf` ON `flf`.`fieldId` = `fields`.`id` INNER JOIN `fieldlayouttabs` `flt` ON `flt`.`id` = `flf`.`tabId` WHERE `flf`.`layoutId`=24 ORDER BY `flt`.`sortOrder`, `flf`.`sortOrder
This MySQL query is being called 90 times:
SELECT `id`, `sectionId`, `fieldLayoutId`, `name`, `handle`, `sortOrder`, `hasTitleField`, `titleFormat`, `uid`, `titleTranslationMethod`, `titleTranslationKeyFormat` FROM `entrytypes` WHERE `dateDeleted` IS NULL
Additional info
- Craft version: 3.5.4
- PHP version: 7.2.33
- Database driver & version: MySQL 5.7.31
- Plugins & versions: Redactor 2.7.1, Redirect Manager 1.1.1, SEOmatic 3.3.15
No modules, a very much vanilla headless Craft setup.