save method being blocked when fetchAll method is called consecutively
See original GitHub issuesave method being blocked when fetchAll method is called consecutively
- Related Issues : #1484
Introduction
When I run a save
method then a fetchAll
method right after, the then
from the save
method doesn’t get called until right before the fetchAll
is done.
Issue Description
I noticed this because I was timing how long the queries were taking. I realized that if I used the save
method by itself, it’s a lot quicker then if I use a fetchAll
right after
Steps to reproduce issue
console.time('save')
console.time('fetchAll')
Model.forge({id: 1}).save(attributes).then(function (newModel) {
console.timeEnd('save');
});
Mode.fetchAll().then(function (allModels) {
console.timeEnd('fetchAll');
});
Expected behaviour
I expect the save to finish in 30ms (as it does when I run it by itself)
Actual behaviour
When I run both save
and fetchAll
one takes 300ms and the other 301ms respectively.
My thoughts
I am guessing this is related to what ryan is seeing in #1484.
From looking at the source code it seems like the save
method has multiple promises and my guess is the fetchAll
promise is being set in between the promises of the save
. Any thoughts?
Note: This does not happen if you have 2 fetchAll
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Well, if knex queries work as expected then it sure looks like some kind of bug in Bookshelf indeed.
Have there been any updates to this? Thanks!