mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-27 18:37:53 +08:00
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
This commit is contained in:
parent
dc59b876d3
commit
f97a1bec22
2 changed files with 16 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue