You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I'm pretty new to Graph QL, and I've been looking into how Strapi handles the n+1 problem of loading data. I set the backend database debug: true, and I ran the following graphql query on the Foodadvisor application:
Here's part of the debug logs I see. Please keep in mind this is only for the restaurants part of the query:
Logs
{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [0],__knexQueryUid: '26914f81-24ad-4a92-92cd-1b40a0770cd2',sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [0],__knexQueryUid: 'ee6f0427-bf2f-4140-9ba4-c78344d0fd99',sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [0],__knexQueryUid: '675cd881-1690-47aa-ad14-855ce1d65bdb',sql: 'select distinct `restaurants`.* from `restaurants` where 1 = ?'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [1],__knexQueryUid: '8c02a128-5b94-4807-9b95-08fef7f03625',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [2],__knexQueryUid: '5aec981c-7e13-4508-8964-6482499ca735',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [3],__knexQueryUid: 'e4932c32-1ca0-4d27-bc15-488e6469e425',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [4],__knexQueryUid: 'a5e2a4d1-cc5c-457d-a106-0864ea3b152d',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [5],__knexQueryUid: '752310fe-ee55-4f17-b363-9665eae31c20',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [6],__knexQueryUid: '18ee0569-0d77-44d2-8920-be9ef7bd1860',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [7],__knexQueryUid: 'a9673a0f-e0a7-4306-8d25-3a266db0abac',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [9],__knexQueryUid: '5ddf848c-eccd-478f-8981-ec6ef2f2572e',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [10],__knexQueryUid: 'a7042eb5-0cec-4109-a4af-b138c4b511ae',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [11],__knexQueryUid: '9f18b66b-bc37-4ace-8b8e-877966ad61c6',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: [12],__knexQueryUid: '3953a8b7-e9ea-47c9-954c-070a5fc629bf',sql: 'select distinct `restaurants`.* from `restaurants` where `restaurants`.`id` in (?)'}
And the same thing for the views part of the query:
Logs
{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['1'],__knexQueryUid: '98410d14-8716-4c63-9779-a6be3b36b66d',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['2'],__knexQueryUid: '99811e9c-8eb1-45de-b4cd-5224c52fcad9',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['3'],__knexQueryUid: 'bd8da4e2-a5f1-45ef-adf2-f72b3a1a9b6f',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['4'],__knexQueryUid: 'fd15a99a-4b1d-4333-9ceb-fa5e4c9661c9',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['5'],__knexQueryUid: '59ab6f1f-987b-4250-b0b8-127f8d9df48f',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['6'],__knexQueryUid: 'a72dd187-a7a6-414d-8d85-9eef46390b26',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['7'],__knexQueryUid: 'f71ae3ca-d10f-4a29-8891-bbf2947baabd',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['8'],__knexQueryUid: 'f436cecf-672c-4366-b43b-2fc6f45b0600',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['9'],__knexQueryUid: 'fad32e0c-a484-4ee6-9ab4-82a4d5e436ed',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['10'],__knexQueryUid: 'f852b6d3-bcbd-46da-ace3-725a92f55d9a',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['11'],__knexQueryUid: 'e01ef6f7-73f1-4e6c-b88b-8c43f2c13149',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}{method: 'select',options: {},timeout: false,cancelOnTimeout: false,bindings: ['12'],__knexQueryUid: 'a373630f-151c-46ae-8a01-e0a9fa111db8',sql: 'select distinct `reviews`.* from `reviews` left join `main`.`restaurants` as `restaurants_1` on `restaurants_1`.`id` = `reviews`.`restaurant` where `restaurants_1`.`id` in (?)'}
And the same thing for the categories part of the query:
Logs
```js
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '1' ],
__knexQueryUid: '483c505a-bcb1-4f03-9b1a-97369bf6d3a5',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '6' ],
__knexQueryUid: '78004bc9-f200-427b-bc65-db490016c467',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '8' ],
__knexQueryUid: 'bf2bed14-71af-4663-9576-a279a1fff30f',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '9' ],
__knexQueryUid: '63172f4a-e230-4162-87a2-b608d981042d',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '12' ],
__knexQueryUid: 'd950d850-09cc-43eb-9b0d-335117447ea7',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '13' ],
__knexQueryUid: '1fdd8a51-4d7f-404c-b512-9bb0cd4bd078',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '14' ],
__knexQueryUid: 'f535b335-4146-4dad-af86-6fba60a9b444',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '10' ],
__knexQueryUid: 'c4ee7022-e95b-4998-b370-76c41f240edd',
sql: 'select distinct categories.* from categories where categories.id in (?)'
}
Hello. I'm pretty new to Graph QL, and I've been looking into how Strapi handles the
n+1
problem of loading data. I set the backend databasedebug: true
, and I ran the following graphql query on the Foodadvisor application:GraphQL query
Here's part of the debug logs I see. Please keep in mind this is only for the restaurants part of the query:
Logs
And the same thing for the views part of the query:
Logs
And the same thing for the categories part of the query:
Logs
```js
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '1' ],
__knexQueryUid: '483c505a-bcb1-4f03-9b1a-97369bf6d3a5',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '6' ],
__knexQueryUid: '78004bc9-f200-427b-bc65-db490016c467',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '8' ],
__knexQueryUid: 'bf2bed14-71af-4663-9576-a279a1fff30f',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '9' ],
__knexQueryUid: '63172f4a-e230-4162-87a2-b608d981042d',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '12' ],
__knexQueryUid: 'd950d850-09cc-43eb-9b0d-335117447ea7',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '13' ],
__knexQueryUid: '1fdd8a51-4d7f-404c-b512-9bb0cd4bd078',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '14' ],
__knexQueryUid: 'f535b335-4146-4dad-af86-6fba60a9b444',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
{
method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '10' ],
__knexQueryUid: 'c4ee7022-e95b-4998-b370-76c41f240edd',
sql: 'select distinct
categories
.* fromcategories
wherecategories
.id
in (?)'}
Looks like strapi makes a database query for every restaurant fetched from the database.
Also, please notice all the unrelated queries about components, likes, opening hours, avg notes etc.
I would love to find out if there's any way to improve this, or if this is a problem that can't be solved.
Just want to learn more about how this system works.
Thanks !
The text was updated successfully, but these errors were encountered: