Mailspring/packages/isomorphic-core/index.js
Mark Hahnenberg 8d21d89f0a [client-app, client-sync] Move messages out of db into compressed flat files
Summary:
Previously we stored message bodies uncompressed inside two different
databases. This was bad for a few reasons:

* Duplicate data in multiple places is an obvious waste of disk space
* Uncompressed data also made the disk footprint bigger than it might
  otherwise be
* Storing these large message bodies in the database made the db file
  larger than it otherwise could have been, increasing the size of
  tables and slowing down queries.

This diff adds support for storing message bodies outside of the
database in compressed flat files. It changes the use of the body column
in the K2 database and the MessageBody table in the edgehill database to
contain a blob of JSON that contains a path to the file on disk. We
use the new format in an incremental fashion without having to perform an
actual database migration by first checking if the body matches our expected
JSON format and treating it appropriately if it doesn't. Both databases refer
to the same file on disk, thus deduplicating the messages bodies. We also
transparently support gzipping the message bodies stored on disk when we
read from/write to the files. The real world space savings depends on the
compressibility of the messages, but we've seen up to ~60% improvement in disk
space usage for certain inboxes. Typical savings are closer to 20%. Also, by
storing messages as separate files on disk we can potentially integrate with
Spotlight search at some point in the future.

Test Plan:
Run locally, make sure that upgrade to this doesn't hose things,
look at size of DB, read emails

Reviewers: evan, spang, halla, juan

Reviewed By: halla, juan

Differential Revision: https://phab.nylas.com/D4422
2017-04-17 22:00:32 -07:00

33 lines
1.4 KiB
JavaScript

/* eslint global-require: 0 */
module.exports = {
Provider: {
Gmail: 'gmail',
IMAP: 'imap',
},
Imap: require('imap'),
Errors: require('./src/errors'),
IMAPErrors: require('./src/imap-errors'),
SMTPErrors: require('./src/smtp-errors'),
loadModels: require('./src/load-models'),
AuthHelpers: require('./src/auth-helpers'),
PromiseUtils: require('./src/promise-utils'),
DatabaseTypes: require('./src/database-types'),
IMAPConnection: require('./src/imap-connection').default,
IMAPConnectionPool: require('./src/imap-connection-pool'),
MessageBodyUtils: require('./src/message-body-utils'),
SendmailClient: require('./src/sendmail-client'),
DeltaStreamBuilder: require('./src/delta-stream-builder'),
HookTransactionLog: require('./src/hook-transaction-log'),
HookIncrementVersionOnSave: require('./src/hook-increment-version-on-save'),
BackoffScheduler: require('./src/backoff-schedulers').BackoffScheduler,
ExponentialBackoffScheduler: require('./src/backoff-schedulers').ExponentialBackoffScheduler,
CommonProviderSettings: require('imap-provider-settings').CommonProviderSettings,
MetricsReporter: require('./src/metrics-reporter').default,
MessageUtils: require('./src/message-utils'),
ModelUtils: require('./src/model-utils').default,
executeJasmine: require('./spec/jasmine/execute').default,
StringUtils: require('./src/string-utils'),
TLSUtils: require('./src/tls-utils'),
DBUtils: require('./src/db-utils'),
}