mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
[client-app] Don't hit contact rankings endpoint until account is ready
Summary: This prevents us from hitting the endpoint before the database for that account is initialized and it's actually syncing. Before this commit, we would throw errors upon adding an account Test Plan: manually add, remove accounts, run benchmark script Reviewers: mark, halla, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D4305
This commit is contained in:
parent
af6e6e669a
commit
58cf02a824
|
@ -4,6 +4,7 @@ import {
|
|||
AccountStore,
|
||||
NylasAPI,
|
||||
NylasAPIRequest,
|
||||
FolderSyncProgressStore,
|
||||
} from 'nylas-exports'
|
||||
import RefreshingJSONCache from './refreshing-json-cache'
|
||||
|
||||
|
@ -77,7 +78,7 @@ class ContactRankingsCacheManager {
|
|||
this.unsubscribers.forEach(unsub => unsub());
|
||||
}
|
||||
|
||||
onAccountsChanged = () => {
|
||||
onAccountsChanged = async () => {
|
||||
const previousIDs = Object.keys(this.accountCaches);
|
||||
const latestIDs = AccountStore.accounts().map(a => a.id);
|
||||
if (_.isEqual(previousIDs, latestIDs)) {
|
||||
|
@ -90,13 +91,18 @@ class ContactRankingsCacheManager {
|
|||
console.log(`ContactRankingsCache: Updating contact rankings; added = ${latestIDs}, removed = ${removedIDs}`);
|
||||
|
||||
for (const newID of newIDs) {
|
||||
// Wait until the account has started syncing before trying to fetch
|
||||
// contact rankings
|
||||
await FolderSyncProgressStore.whenCategoryListSynced(newID)
|
||||
this.accountCaches[newID] = new ContactRankingsCache(newID);
|
||||
this.accountCaches[newID].start();
|
||||
}
|
||||
|
||||
for (const removedID of removedIDs) {
|
||||
this.accountCaches[removedID].end();
|
||||
this.accountCaches[removedID] = null;
|
||||
if (this.accountCaches[removedID]) {
|
||||
this.accountCaches[removedID].end();
|
||||
this.accountCaches[removedID] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue