mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
A folders contents need refreshing if we don't have any saved state, or if the sort criteria is different than the cache, or if the filter is different than the cache. The previous logic required a refresh if the cached filter == nil. This is almost always the case: opening a plain folder has a nil filter. The only filter criteria is added in the parsing step (ie: inMailbox). This meant every directory change that wasn't already filtered required a Refresh. The new logic fixes this. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package cache
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib/log"
|
|
"git.sr.ht/~rjarry/aerc/worker/types"
|
|
"git.sr.ht/~rockorager/go-jmap"
|
|
)
|
|
|
|
type FolderContents struct {
|
|
MailboxID jmap.ID
|
|
QueryState string
|
|
Filter *types.SearchCriteria
|
|
Sort []*types.SortCriterion
|
|
MessageIDs []jmap.ID
|
|
}
|
|
|
|
func (c *JMAPCache) GetFolderContents(mailboxId jmap.ID) (*FolderContents, error) {
|
|
key := folderContentsKey(mailboxId)
|
|
buf, err := c.get(key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
m := new(FolderContents)
|
|
err = unmarshal(buf, m)
|
|
if err != nil {
|
|
log.Debugf("cache format has changed, purging foldercontents")
|
|
if e := c.purge("foldercontents/"); e != nil {
|
|
log.Errorf("foldercontents cache purge: %s", e)
|
|
}
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (c *JMAPCache) PutFolderContents(mailboxId jmap.ID, m *FolderContents) error {
|
|
buf, err := marshal(m)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return c.put(folderContentsKey(mailboxId), buf)
|
|
}
|
|
|
|
func (c *JMAPCache) DeleteFolderContents(mailboxId jmap.ID) error {
|
|
return c.delete(folderContentsKey(mailboxId))
|
|
}
|
|
|
|
func folderContentsKey(mailboxId jmap.ID) string {
|
|
return "foldercontents/" + string(mailboxId)
|
|
}
|
|
|
|
func (f *FolderContents) NeedsRefresh(
|
|
filter *types.SearchCriteria, sort []*types.SortCriterion,
|
|
) bool {
|
|
return f.QueryState == "" ||
|
|
!reflect.DeepEqual(f.Sort, sort) ||
|
|
!reflect.DeepEqual(f.Filter, filter)
|
|
}
|