question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

save method being blocked when fetchAll method is called consecutively

See original GitHub issue

save method being blocked when fetchAll method is called consecutively

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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ricardogracacommented, Jul 21, 2017

Well, if knex queries work as expected then it sure looks like some kind of bug in Bookshelf indeed.

0reactions
lalitkapoorcommented, Oct 12, 2017

Have there been any updates to this? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Method call to Future.get() blocks. Is that really desirable?
Future offers you method isDone() which is not blocking and returns true if computation has completed, false otherwise. Future.get() is used ...
Read more >
Python cursor's fetchall, fetchmany(), fetchone() to ... - PYnative
When called repeatedly, this method fetches the next set of rows of a query result and returns a list of tuples. If no...
Read more >
How to Handle Unsuccessful Fetch API Calls in JavaScript
The promise state is “fulfilled” but we handled the error now. Now we can see the proof that the promise is rejected and...
Read more >
Transaction locking and row versioning guide - SQL Server
This is called concurrency control. Concurrency control theory has two classifications for the methods of instituting concurrency control:.
Read more >
Java CompletableFuture Tutorial with Examples - CalliCoder
In this post I'll give you a detailed explanation of CompletableFuture and all its methods using simple examples. What's a CompletableFuture?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found