Mailspring/spec
Ben Gotow e1882ab61a feat(counts): Unread counts for all folders and labels across all accounts
Summary:
This diff replaces the UnreadCountStore with a better approach that is able to track unread counts for all folders/labels without continuous (and cripplingly slow) SELECT COUNT(*) queries.

When models are written to the database, we currently don't send out notifications with the "previous" state of those objects in the database. This makes it hard to determine how to update counters. (In the future, we may need to do this for live queries). Unfortunately, getting the "previous" state is going to be very hard, because multiple windows write to the database and the "previous" state we have might be outdated. We'd almost have to run a "SELECT" right before every "REPLACE INTO".

I created an API that allows you to register observers around persistModel and unpersistModel. With this API, you can run queries before and after the database changes are made and pluck just the "before" state you're interested in.

The `ThreadCountsStore` uses this API to determine the impact of persisting a set of threads on the unread counts of different labels. Before the threads are saved, it says "how much do these thread IDs contribute to unread counts currently?". After the write is complete it looks at the models and computes the difference between the old count impact and the new count impact, and updates the counters.

I decided not to attach the unread count to the Label objects themselves because 1) they update frequently and 2) most things observing the DatabaseStore for categories do not care about counts, so they would be updating unnecessarily.

The AccountSidebar now listens to the ThreadCountsStore as well as the CategoryStore, and there's a new preference in the General tab for turning off the counts.

Test Plan: Tests are a work in progress, want to get feedback first!

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2232
2015-11-23 17:12:22 -08:00
..
components fix(composer): Fix several composer issues and refactor Contenteditable 2015-11-18 15:22:31 -08:00
fixtures feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
models fix(names): "Olivia" should not be caught by name cleanup 2015-11-13 11:42:37 -08:00
stores feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
tasks refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
action-bridge-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
auto-update-manager-spec.coffee fix(specs): Don't check for updates during spec runs 2015-11-02 11:56:11 -08:00
buffered-process-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
clipboard-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
component-registry-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
database-object-registry-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
database-view-spec.coffee feat(trash): Trash for Gmail, and architectural changes for common tasks 2015-10-21 10:38:00 -07:00
dom-utils-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
jasmine-helper.coffee fix(specs): Ternary operator in jasmine-helper was valid coffee... 2015-11-17 17:48:32 -08:00
jasmine-jquery.js refactor(dir): move exports to src/global and consolidate tests 2015-10-02 09:19:37 -07:00
jasmine.js refactor(dir): move exports to src/global and consolidate tests 2015-10-02 09:19:37 -07:00
launch-services-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
menu-manager-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
model-view-selection-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
model-view-spec.coffee feat(selection): add selection of read, unread, starred, etc 2015-11-09 10:03:55 -05:00
module-cache-spec.coffee fix(specs): Update specs following 0.29.2 > 0.34.3 move 2015-11-17 17:40:06 -08:00
n1-spec-reporter.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
nylas-api-spec.coffee fix(sync): Request all labels / folders to avoid paging and missing inbox 2015-10-03 23:53:59 -07:00
nylas-env-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
nylas-protocol-handler-spec.coffee fix(specs): Update specs following 0.29.2 > 0.34.3 move 2015-11-17 17:40:06 -08:00
nylas-test-utils.coffee fix(specs): Update specs following 0.29.2 > 0.34.3 move 2015-11-17 17:40:06 -08:00
package-manager-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
package-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
quoted-html-parser-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
quoted-plain-text-parser-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
spec-bootstrap.coffee fix(build): bail if script/bootstrap fails and enhance test output 2015-11-23 14:34:18 -05:00
spec-helper-platform.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
spec-helper.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
spec-suite.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
style-manager-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00
styles-element-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
theme-manager-spec.coffee refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
time-reporter.coffee refactor(utils): switch to regular underscore 2015-05-19 16:06:59 -07:00
undo-manager-spec.coffee fix(composer): support Chinese & others - handle composition events 2015-10-30 20:03:33 -04:00
utils-spec.coffee refactor(spec) move spec-nylas to spec 2015-10-01 21:39:44 -07:00