Mailspring/internal_packages
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
..
account-sidebar feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
attachments refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
category-picker refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
composer fix(specs): Update composer-view-spec to use renamed functions 2015-11-18 15:51:48 -08:00
composer-signature refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
composer-spellcheck fix(composer): Fix several composer issues and refactor Contenteditable 2015-11-18 15:22:31 -08:00
events refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
feedback refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
inbox-contact-elements refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
message-autoload-images refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
message-list feat(dark-mode): Double invert filter for nice dark HTML bodies 2015-11-20 18:53:34 -08:00
mode-switch refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
notification-mailto refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
notification-update-available refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
notifications refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
onboarding refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
plugins refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
preferences feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
search-bar fix(search): Execute search for subject, autoselect first item 2015-11-18 12:35:19 -08:00
sidebar-fullcontact refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
system-tray feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
thread-list fix(search): Execute search for subject, autoselect first item 2015-11-18 12:35:19 -08:00
tooltip refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
ui-dark feat(dark-mode): Double invert filter for nice dark HTML bodies 2015-11-20 18:53:34 -08:00
ui-light refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
undo-redo refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
unread-notifications refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
worker-sync refactor(env): new NylasEnv global 2015-11-17 16:41:20 -08:00
worker-ui fix(draft): fix showing of incorrect body when pending send 2015-11-18 12:32:07 -08:00