dirlist: actually honor the DirInfo

Currently the dirlist ignores the counts provided by the dirInfo.
However some of the workers can actually provide accurate counts much quicker
than if we count the flags.

Eventually we will also want to enable displaying counts for background folders,
where the brute force counting won't work as none of the headers are fetched yet.

This commit models it in an opt-in manner, if the flag isn't set then we still
count the messages manually.
This commit is contained in:
Reto Brunner 2020-02-15 14:14:43 +01:00 committed by Drew DeVault
parent bd4df53009
commit 66b68f35b3
2 changed files with 39 additions and 25 deletions

View file

@ -50,6 +50,9 @@ type DirectoryInfo struct {
// The number of unread messages // The number of unread messages
Unseen int Unseen int
// set to true if the value counts are accurate
AccurateCounts bool
} }
// A MessageInfo holds information about the structure of a message // A MessageInfo holds information about the structure of a message

View file

@ -171,32 +171,17 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
} }
func (dirlist *DirectoryList) getRUEString(name string) string { func (dirlist *DirectoryList) getRUEString(name string) string {
totalUnseen := 0 msgStore, ok := dirlist.MsgStore(name)
totalRecent := 0 if !ok {
totalExists := 0 return ""
if msgStore, ok := dirlist.MsgStore(name); ok { }
for _, msg := range msgStore.Messages { var totalRecent, totalUnseen, totalExists int
if msg == nil { if msgStore.DirInfo.AccurateCounts {
continue totalRecent = msgStore.DirInfo.Recent
} totalUnseen = msgStore.DirInfo.Unseen
seen := false
recent := false
for _, flag := range msg.Flags {
if flag == models.SeenFlag {
seen = true
} else if flag == models.RecentFlag {
recent = true
}
}
if !seen {
if recent {
totalRecent++
} else {
totalUnseen++
}
}
}
totalExists = msgStore.DirInfo.Exists totalExists = msgStore.DirInfo.Exists
} else {
totalRecent, totalUnseen, totalExists = countRUE(msgStore)
} }
rueString := "" rueString := ""
if totalRecent > 0 { if totalRecent > 0 {
@ -395,3 +380,29 @@ func (dirlist *DirectoryList) getSortCriteria() []*types.SortCriterion {
} }
return criteria return criteria
} }
func countRUE(msgStore *lib.MessageStore) (recent, unread, exist int) {
for _, msg := range msgStore.Messages {
if msg == nil {
continue
}
seen := false
isrecent := false
for _, flag := range msg.Flags {
if flag == models.SeenFlag {
seen = true
} else if flag == models.RecentFlag {
isrecent = true
}
}
if !seen {
if isrecent {
recent++
} else {
unread++
}
}
exist++
}
return recent, unread, exist
}