fix(sync-status): Use sync progress from K2

Summary:
Sister diff to D3817

syncState on folders may contain arbitrarily long arrays of UIDs
(particularly, failedUIDs). If we serialize this JSON column to
edgehill.db, we can end up serializing very large objects when
persisting the local task queue. When the queue contains many tasks,
this can balloon the JSON blob to megabytes, causing the main window and
the worker window to become unresponsive.

The UI doesn't need to know about IMAP bookkeeping internals, so
serialize the sync progress instead of the sync state. This has the
advantages that (1) we don't need to worry about future keys added
to the syncState being large and (2) when we add Exchange support
we already have an abstraction for sync progress.

Test Plan: manual

Reviewers: juan, mark, halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3819
This commit is contained in:
Christine Spang 2017-02-01 07:16:02 -08:00
parent e4ce1f8e1e
commit bf8818d208
3 changed files with 9 additions and 18 deletions

2
src/K2

@ -1 +1 @@
Subproject commit c993ec3b8749e73d4eb1ab8f457debfa21a05858
Subproject commit 5b659382d61f2774040be1e310f380bd7e0bea78

View file

@ -71,9 +71,9 @@ export default class Category extends Model {
modelKey: 'displayName',
jsonKey: 'display_name',
}),
syncState: Attributes.Object({
modelKey: 'syncState',
jsonKey: 'sync_state',
syncProgress: Attributes.Object({
modelKey: 'syncProgress',
jsonKey: 'sync_progress',
}),
});

View file

@ -88,20 +88,11 @@ class NylasSyncStatusStore extends NylasStore {
const updates = {}
for (const folder of folders) {
const name = folder.name || folder.displayName
const {uidnext, fetchedmin, fetchedmax, minUID, oldestProcessedDate} = folder.syncState || {}
if (uidnext) {
// TODO: when we unify the databases, we shouldn't need code to
// calculate this in two different places anymore
const progress = (+fetchedmax - +fetchedmin + 1) / (uidnext - minUID + 1)
updates[name] = {
progress,
total: uidnext,
oldestProcessedDate: oldestProcessedDate ? new Date(oldestProcessedDate) : new Date(),
}
} else {
// We don't have a uidnext if the sync hasn't started at all,
// but we've found the folder.
updates[name] = {progress: 0, total: 0, oldestProcessedDate: new Date()}
const {approxPercentComplete, approxTotal, oldestProcessedDate} = folder.syncProgress || {};
updates[name] = {
progress: approxPercentComplete || 0,
total: approxTotal || 0,
oldestProcessedDate: oldestProcessedDate ? new Date(oldestProcessedDate) : new Date(),
}
}
this._updateState(accountId, {folderSyncProgress: updates})