From f97a1bec22e934a37b3eaba3773fe751880ca130 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 16 Feb 2015 17:24:23 -0800 Subject: [PATCH] fix(unread): Use the API instead of the database for unread counts Summary: Populates the unread tag counts using new API feature instead of using the local cache. Test Plan: No tests for now :-( Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1195 --- .../lib/account-sidebar-store.coffee | 15 ++++++++------- src/flux/models/tag.coffee | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal_packages/account-sidebar/lib/account-sidebar-store.coffee b/internal_packages/account-sidebar/lib/account-sidebar-store.coffee index e6073a452..e68931c55 100644 --- a/internal_packages/account-sidebar/lib/account-sidebar-store.coffee +++ b/internal_packages/account-sidebar/lib/account-sidebar-store.coffee @@ -60,13 +60,14 @@ AccountSidebarStore = Reflux.createStore # Some tags don't have unread counts return if tag.id in ['archive', 'drafts', 'sent', 'trash'] - DatabaseStore.count(Thread, [ - Thread.attributes.namespaceId.equal(namespace.id), - Thread.attributes.unread.equal(true), - Thread.attributes.tags.contains(tag.id), - ]).then (count) => - @_unreadCounts[tag.id] = count - @trigger(@) + # Make a web request for unread count + atom.inbox.makeRequest + method: 'GET' + path: "/n/#{namespace.id}/tags/#{tag.id}" + success: (json) => + tag = (new Tag).fromJSON(json) + @_unreadCounts[tag.id] = tag.unreadCount + @trigger(@) # Unfortunately, the joins necessary to compute unread counts are expensive. # Rather than update unread counts every time threads change in the database, diff --git a/src/flux/models/tag.coffee b/src/flux/models/tag.coffee index 23e1eafb6..b187de81c 100644 --- a/src/flux/models/tag.coffee +++ b/src/flux/models/tag.coffee @@ -8,5 +8,13 @@ class Tag extends Model 'name': Attributes.String queryable: true modelKey: 'name' + 'readonly': Attributes.Boolean + modelKey: 'readonly' + 'unreadCount': Attributes.Number + modelKey: 'unreadCount' + jsonKey: 'unread_count' + 'threadCount': Attributes.Number + modelKey: 'threadCount' + jsonKey: 'thread_count' module.exports = Tag \ No newline at end of file