diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2023-08-30 16:17:59 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-08-31 17:36:34 +0200 |
commit | 9ba1c3408c34d1b9da343b00ea963d23138d5037 (patch) | |
tree | c9338b3df5e0562c3eb71930ee7e4a21a65f842b /worker | |
parent | 965d38097cbc4d429496622670f23c492324aaf2 (diff) | |
download | aerc-9ba1c3408c34d1b9da343b00ea963d23138d5037.tar.gz |
notmuch: internally sort threads newest first
For proper thread ordering, notmuch needs to use a SORT_NEWEST_FIRST
sort order in it's query, and then we reverse the thread order. Also
give a maximum guess for size of slice we'll be returning.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/notmuch/lib/database.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 3b9de011..9a6689c4 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -117,12 +117,18 @@ func (db *DB) ThreadsFromQuery(ctx context.Context, q string) ([]*types.Thread, return nil, err } defer query.Close() + // To get proper ordering of threads, we always sort newest first + query.Sort(notmuch.SORT_NEWEST_FIRST) threads, err := query.Threads() if err != nil { return nil, err } + n, err := query.CountMessages() + if err != nil { + return nil, err + } defer threads.Close() - var res []*types.Thread + res := make([]*types.Thread, 0, n) for threads.Next() { select { case <-ctx.Done(): @@ -136,6 +142,10 @@ func (db *DB) ThreadsFromQuery(ctx context.Context, q string) ([]*types.Thread, thread.Close() } } + // Reverse the slice + for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 { + res[i], res[j] = res[j], res[i] + } return res, err } |