mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-06 04:35:30 +08:00
[local-sync] Serialize category sync progress to edgehill rather than syncState
Summary: 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/D3817
This commit is contained in:
parent
efba50bd9f
commit
c6f371aa0f
1 changed files with 30 additions and 6 deletions
|
@ -1,9 +1,11 @@
|
|||
const _ = require('underscore')
|
||||
const crypto = require('crypto')
|
||||
const {DatabaseTypes: {JSONColumn}} = require('isomorphic-core');
|
||||
const {formatImapPath} = require('../shared/imap-paths-utils');
|
||||
import _ from 'underscore'
|
||||
import crypto from 'crypto'
|
||||
import {DatabaseTypes} from 'isomorphic-core'
|
||||
import {formatImapPath} from '../shared/imap-paths-utils'
|
||||
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const {JSONColumn} = DatabaseTypes
|
||||
|
||||
export default (sequelize, Sequelize) => {
|
||||
return sequelize.define('folder', {
|
||||
id: { type: Sequelize.STRING(65), primaryKey: true },
|
||||
accountId: { type: Sequelize.STRING, allowNull: false },
|
||||
|
@ -74,6 +76,24 @@ module.exports = (sequelize, Sequelize) => {
|
|||
return this.save();
|
||||
},
|
||||
|
||||
syncProgress() {
|
||||
if (!this.syncState) {
|
||||
return {
|
||||
approxPercentComplete: 0,
|
||||
approxTotal: 0,
|
||||
oldestProcessedDate: new Date(),
|
||||
}
|
||||
}
|
||||
const {fetchedmax, fetchedmin, uidnext, minUID, oldestProcessedDate} = this.syncState;
|
||||
return {
|
||||
// based on % of uid space scanned, but space may be sparse
|
||||
approxPercentComplete: (+fetchedmax - +fetchedmin + 1) /
|
||||
(uidnext - Math.min(minUID, fetchedmin) + 1),
|
||||
approxTotal: uidnext,
|
||||
oldestProcessedDate: oldestProcessedDate,
|
||||
}
|
||||
},
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
id: `${this.id}`,
|
||||
|
@ -81,7 +101,11 @@ module.exports = (sequelize, Sequelize) => {
|
|||
object: 'folder',
|
||||
name: this.role,
|
||||
display_name: formatImapPath(this.name),
|
||||
sync_state: this.syncState,
|
||||
sync_progress: this.syncProgress(),
|
||||
// intentionally overwrite any sync states stored in edgehill.db,
|
||||
// since it may contain long arrays and cause perf degredation
|
||||
// when serialized repeatedly
|
||||
sync_state: null,
|
||||
};
|
||||
},
|
||||
},
|
Loading…
Add table
Reference in a new issue