[client-app] Don't delay db queries unless we are retrying

Summary:
After introducing retry logic, we would always defer db queries to the
next tick even if there was no retry delay present.

This would cause almost all db queries take more than 100ms even if the
actual db operation was really fast. This affected app performance
negatively

Test Plan: manual

Reviewers: evan, halla, mark

Reviewed By: halla, mark

Differential Revision: https://phab.nylas.com/D4282
This commit is contained in:
Juan Tejada 2017-03-29 10:57:51 -07:00
parent 9d15ff7ff7
commit 745dac7582

View file

@ -376,8 +376,14 @@ class DatabaseStore extends NylasStore {
// unable to execute it. Handle this case silently unless it's persistent.
while (!results) {
try {
// wait for the currentDelay before continuing
await new Promise((resolve) => setTimeout(resolve, scheduler.currentDelay()))
if (scheduler.currentDelay() > 0) {
// Setting a tiemout for 0 will still defer execution of this function
// to the next tick of the event loop.
// We don't want to unnecessarily defer and delay every single query,
// so we only set the timer when we are actually backing off for a
// retry.
await new Promise((resolve) => setTimeout(resolve, scheduler.currentDelay()))
}
let stmt = this._preparedStatementCache.get(query);
if (!stmt) {