Mailspring/internal_packages/account-sidebar/lib
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-divider-item.cjsx fix(naming): Move atom/inbox/nilas refs to Nylas 2015-05-15 11:07:28 -07:00
account-sidebar-item.cjsx fix(account-sidebar): make folder and label names wrap elegantly. fixes T3402. 2015-08-31 10:47:25 -07:00
account-sidebar-mail-view-item.cjsx feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
account-sidebar-sheet-item.cjsx fix(icons): New artwork for a few initial packages, labels 2015-10-03 23:34:43 -07:00
account-sidebar-store.coffee feat(sidebar): Hierarchical folders/labels in the sidebar, rendering perf 2015-10-22 10:53:57 -07:00
account-sidebar.cjsx feat(counts): Unread counts for all folders and labels across all accounts 2015-11-23 17:12:22 -08:00
account-switcher.cjsx fix(prefs): Move to a sheet rather than a window, use configSchema 2015-11-23 12:20:51 -08:00
main.cjsx fix(account-switcher): Switcher should not be part of the scroll region in the sidebar 2015-10-04 00:19:29 -07:00