diff options
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 } |