Mailspring/spec/stores
Ben Gotow ea76b7c442 feat(transactions): Explicit (and faster) database transactions
Summary:
Until now, we've been hiding transactions beneath the surface. When you call persistModel, you're implicitly creating a transaction.
You could explicitly create them with `atomically`..., but there were several critical problems that are fixed in this diff:

- Calling persistModel / unpersistModel within a transaction could cause the DatabaseStore to trigger. This could result in other parts of the app making queries /during/
  the transaction, potentially before the COMMIT occurred and saved the changes. The new, explicit inTransaction syntax holds all changes until after COMMIT and then triggers.

- Calling atomically and then calling persistModel inside that resulted in us having to check whether a transaction was present and was gross.

- Many parts of the code ran extensive logic inside a promise chained within `atomically`:

  BAD:

```
  DatabaseStore.atomically =>
   DatabaseStore.persistModel(draft) =>
     GoMakeANetworkRequestThatReturnsAPromise
```

OVERWHELMINGLY BETTER:

```
  DatabaseStore.inTransaction (t) =>
     t.persistModel(draft)
  .then =>
    GoMakeANetworkRequestThatReturnsAPromise
```

Having explicit transactions also puts us on equal footing with Sequelize and other ORMs. Note that you /have/ to call DatabaseStore.inTransaction (t) =>. There is no other way to access the methods that let you alter the database. :-)

Other changes:
- This diff removes Message.labels and the Message-Labels table. We weren't using Message-level labels anywhere, and the table could grow very large.
- This diff changes the page size during initial sync from 250 => 200 in an effort to make transactions a bit faster.

Test Plan: Run tests!

Reviewers: juan, evan

Reviewed By: juan, evan

Differential Revision: https://phab.nylas.com/D2353
2015-12-17 11:46:05 -08:00
..
account-store-spec.coffee feat(account-prefs): Adds new page for Account in preferences 2015-12-10 15:27:29 -08:00
contact-store-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
database-setup-query-builder-spec.coffee fix(counts): Ensure serial execution of persistModels, unpersistModels 2015-11-25 12:17:00 -08:00
database-store-spec.coffee feat(transactions): Explicit (and faster) database transactions 2015-12-17 11:46:05 -08:00
database-transaction-spec.coffee feat(transactions): Explicit (and faster) database transactions 2015-12-17 11:46:05 -08:00
draft-store-proxy-spec.coffee feat(transactions): Explicit (and faster) database transactions 2015-12-17 11:46:05 -08:00
draft-store-spec.coffee feat(transactions): Explicit (and faster) database transactions 2015-12-17 11:46:05 -08:00
file-download-store-spec.coffee fix(downloads): Improve inline attachment handling 2015-12-07 15:00:25 -08:00
file-upload-store-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
focused-contacts-store-spec.coffee
focused-content-store-spec.coffee
focused-mail-view-store-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
message-store-spec.coffee feat(observables): Implementation of observables to replace some stores 2015-12-07 16:52:46 -08:00
task-queue-spec.coffee feat(observables): Implementation of observables to replace some stores 2015-12-07 16:52:46 -08:00
thread-counts-store-spec.coffee feat(transactions): Explicit (and faster) database transactions 2015-12-17 11:46:05 -08:00
unread-badge-store-spec.coffee fix(badge): Badge respects option in prefs 2015-11-30 19:17:35 -08:00