annotate src/lib-storage/index/index-sort.c @ 6547:7a207cbc008b HEAD

Don't assert-crash with node.sort_id != 0.
author Timo Sirainen <tss@iki.fi>
date Tue, 16 Oct 2007 17:21:19 +0300
parents a53bc41fade4
children bf5293708132
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6429
65c69a53a7be Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
1 /* Copyright (c) 2006-2007 Dovecot authors, see the included COPYING file */
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
2
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
3 /* The idea in here is that for each used primary sort condition there's
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
4 a 32bit integer in the index file which specifies the sort order. So when
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
5 sorting we simply look up the sort IDs and sort the messages by them.
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
6
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
7 Sort IDs are allocated in two ways:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
8
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
9 1) Time and size fields can be directly used as sort IDs, so we simply
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
10 use them directly as the missing sort IDs.
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
11
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
12 2) Strings can't be used as sort IDs directly. The way they're currently
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
13 handled is that the whole 32bit integer space is used for them and whenever
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
14 adding a string, the available space is halved and the new ID is added in
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
15 the middle. For example if we add one mail the first time, it gets ID
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
16 2^31. If we then add two mails which are sorted before the first one, they
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
17 get IDs 2^31/3 and 2^31/3*2. Once we run out of the available space between
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
18 IDs, a large amount of the IDs are renumbered.
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
19
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
20 We try to avoid looking at mails' contents as much as possible. For case 1)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
21 IDs it's simple because we need to get only the new mails' sort fields once
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
22 and use them as sort IDs. For case 2) we'll have to start looking at the
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
23 strings from older mails as well. To minimize this, we first sort the
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
24 existing sort IDs. After that we start inserting the new mails into the
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
25 sorted array by looking the position using binary search. This minimizes
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
26 the number of lookups we have to do for the old mails. Usually only a few
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
27 mails have been added, so this should be faster than other sort methods.
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
28 */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
29
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
30 #include "lib.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
31 #include "array.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
32 #include "bsearch-insert-pos.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
33 #include "str.h"
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
34 #include "unichar.h"
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
35 #include "message-address.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
36 #include "imap-base-subject.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
37 #include "index-storage.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
38 #include "index-sort.h"
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
39
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
40 #include <stdlib.h>
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
41
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
42 #define RENUMBER_SPACE 100
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
43
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
44 struct mail_sort_node {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
45 uint32_t seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
46 uint32_t sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
47 };
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
48 ARRAY_DEFINE_TYPE(mail_sort_node, struct mail_sort_node);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
49
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
50 struct mail_search_sort_program {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
51 struct mailbox_transaction_context *t;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
52 enum mail_sort_type sort_program[MAX_SORT_PROGRAM_SIZE];
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
53 const char *primary_sort_header;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
54 struct mail *temp_mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
55
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
56 ARRAY_TYPE(mail_sort_node) nodes;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
57 const struct mail_sort_node *nodes_ptr;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
58 unsigned int nodes_count, iter_idx;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
59
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
60 ARRAY_TYPE(mail_sort_node) all_nodes;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
61
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
62 uint32_t ext_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
63 uint32_t prev_seq, last_sorted_seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
64
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
65 unsigned int reverse:1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
66 unsigned int skipped_mails:1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
67 unsigned int sort_ids_added:1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
68 };
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
69
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
70 struct sort_cmp_context {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
71 struct mail_search_sort_program *program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
72 struct mail *mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
73
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
74 uint32_t cache_seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
75 enum mail_sort_type cache_type;
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
76 uint32_t cache_value;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
77 const char *cache_str;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
78 };
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
79
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
80 static struct sort_cmp_context static_node_cmp_context;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
81
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
82 struct mail_search_sort_program *
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
83 index_sort_program_init(struct mailbox_transaction_context *t,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
84 const enum mail_sort_type *sort_program)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
85 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
86 struct index_mailbox *ibox = (struct index_mailbox *)t->box;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
87 struct mail_search_sort_program *program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
88 const char *name;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
89 unsigned int i;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
90
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
91 if (sort_program == NULL || sort_program[0] == MAIL_SORT_END)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
92 return NULL;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
93
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
94 /* we support internal sorting by the primary condition */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
95 program = i_new(struct mail_search_sort_program, 1);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
96 program->t = t;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
97 program->temp_mail = mail_alloc(t, 0, NULL);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
98 program->reverse =
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
99 (program->sort_program[0] & MAIL_SORT_FLAG_REVERSE) != 0;
4596
bf4e98a0de3f Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents: 4594
diff changeset
100 i_array_init(&program->nodes, 64);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
101
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
102 for (i = 0; i < MAX_SORT_PROGRAM_SIZE; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
103 program->sort_program[i] = sort_program[i];
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
104 if (sort_program[i] == MAIL_SORT_END)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
105 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
106 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
107 if (i == MAX_SORT_PROGRAM_SIZE)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
108 i_panic("index_sort_program_init(): Invalid sort program");
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
109
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
110 switch (program->sort_program[0] & MAIL_SORT_MASK) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
111 case MAIL_SORT_ARRIVAL:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
112 name = "rdate";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
113 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
114 case MAIL_SORT_CC:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
115 name = "sort-c";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
116 program->primary_sort_header = "Cc";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
117 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
118 case MAIL_SORT_DATE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
119 name = "date";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
120 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
121 case MAIL_SORT_FROM:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
122 name = "sort-f";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
123 program->primary_sort_header = "From";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
124 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
125 case MAIL_SORT_SIZE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
126 name = "size";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
127 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
128 case MAIL_SORT_SUBJECT:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
129 name = "sort-s";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
130 program->primary_sort_header = "Subject";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
131 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
132 case MAIL_SORT_TO:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
133 name = "sort-t";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
134 program->primary_sort_header = "To";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
135 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
136 default:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
137 i_unreached();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
138 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
139 program->ext_id =
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
140 mail_index_ext_register(ibox->index, name, 0,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
141 sizeof(uint32_t), sizeof(uint32_t));
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
142 return program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
143 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
144
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
145 void index_sort_program_deinit(struct mail_search_sort_program **_program)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
146 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
147 struct mail_search_sort_program *program = *_program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
148
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
149 *_program = NULL;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
150 mail_free(&program->temp_mail);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
151 array_free(&program->nodes);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
152 i_free(program);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
153 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
154
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
155 static const char *get_first_mailbox(struct mail *mail, const char *header)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
156 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
157 struct message_address *addr;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
158 const char *str;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
159
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
160 if (mail_get_first_header_utf8(mail, header, &str) <= 0)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
161 return "";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
162
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
163 addr = message_address_parse(pool_datastack_create(),
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
164 (const unsigned char *)str,
4635
210bb1ff0e6e Added fill_missing parameter to message_address_parse() which specifies if
Timo Sirainen <tss@iki.fi>
parents: 4596
diff changeset
165 strlen(str), 1, TRUE);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
166 return addr != NULL ? addr->mailbox : "";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
167 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
168
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
169 static const char *
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
170 sort_header_get(enum mail_sort_type sort_type, struct mail *mail, uint32_t seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
171 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
172 const char *str;
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
173 string_t *buf;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
174
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
175 mail_set_seq(mail, seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
176 switch (sort_type & MAIL_SORT_MASK) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
177 case MAIL_SORT_SUBJECT:
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
178 if (mail_get_first_header(mail, "Subject", &str) <= 0)
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
179 return "";
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
180 return imap_get_base_subject_cased(pool_datastack_create(),
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
181 str, NULL);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
182 case MAIL_SORT_CC:
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
183 str = get_first_mailbox(mail, "Cc");
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
184 break;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
185 case MAIL_SORT_FROM:
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
186 str = get_first_mailbox(mail, "From");
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
187 break;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
188 case MAIL_SORT_TO:
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
189 str = get_first_mailbox(mail, "To");
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
190 break;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
191 default:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
192 i_unreached();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
193 }
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
194
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
195 buf = t_str_new(128);
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
196 (void)uni_utf8_to_decomposed_titlecase(str, (size_t)-1, buf);
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
197 return str_c(buf);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
198 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
199
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
200 static uint32_t sort_get_arrival(struct mail *mail)
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
201 {
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
202 time_t t;
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
203
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
204 if (mail_get_received_date(mail, &t) < 0)
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
205 t = 0;
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
206
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
207 i_assert(t != (time_t)-1);
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
208 /* FIXME: truncation isn't good.. */
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
209 return t <= 0 ? 1 :
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
210 (t >= (uint32_t)-1 ? (uint32_t)-1 : t + 1);
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
211 }
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
212
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
213 static uint32_t sort_get_date(struct mail *mail)
6546
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
214 {
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
215 time_t t;
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
216
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
217 if (mail_get_date(mail, &t, NULL) < 0)
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
218 t = 0;
6546
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
219 if (t == 0) {
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
220 if (mail_get_received_date(mail, &t) < 0)
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
221 return 1;
6546
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
222 }
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
223 i_assert(t != (time_t)-1);
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
224 /* FIXME: truncation isn't good.. */
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
225 return t <= 0 ? 1 :
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
226 (t >= (uint32_t)-1 ? (uint32_t)-1 : t + 1);
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
227 }
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
228
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
229 static uint32_t sort_get_size(struct mail *mail)
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
230 {
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
231 uoff_t size;
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
232
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
233 if (mail_get_virtual_size(mail, &size) < 0)
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
234 return 1;
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
235
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
236 /* FIXME: elsewhere we support 64bit message sizes, but here
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
237 we support only 32bit sizes.. It's a bit too much trouble
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
238 to support 64bit here currently, so until such messages
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
239 actually start showing up somewhere, 32bit is enough */
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
240 i_assert(size < (uint32_t)-1);
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
241 return size + 1;
6546
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
242 }
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
243
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
244 static int sort_node_cmp_type(struct sort_cmp_context *ctx,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
245 const enum mail_sort_type *sort_program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
246 const struct mail_sort_node *n1,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
247 const struct mail_sort_node *n2)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
248 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
249 enum mail_sort_type sort_type;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
250 const char *str1, *str2;
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
251 uint32_t time1, time2, size1, size2;
4935
f768dd773e6b Compiler warning fix
Timo Sirainen <tss@iki.fi>
parents: 4635
diff changeset
252 int ret = 0;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
253
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
254 sort_type = *sort_program & MAIL_SORT_MASK;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
255 switch (sort_type) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
256 case MAIL_SORT_CC:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
257 case MAIL_SORT_FROM:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
258 case MAIL_SORT_TO:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
259 case MAIL_SORT_SUBJECT:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
260 t_push();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
261 str1 = n1->seq == ctx->cache_seq &&
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
262 ctx->cache_type == sort_type ? ctx->cache_str :
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
263 sort_header_get(sort_type, ctx->mail, n1->seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
264 str2 = sort_header_get(sort_type, ctx->mail, n2->seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
265
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
266 ret = strcmp(str1, str2);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
267 t_pop();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
268 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
269 case MAIL_SORT_ARRIVAL:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
270 if (n1->seq == ctx->cache_seq && ctx->cache_type == sort_type)
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
271 time1 = ctx->cache_value;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
272 else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
273 mail_set_seq(ctx->mail, n1->seq);
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
274 time1 = sort_get_arrival(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
275 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
276
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
277 mail_set_seq(ctx->mail, n2->seq);
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
278 time2 = sort_get_arrival(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
279
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
280 ret = time1 < time2 ? -1 :
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
281 (time1 > time2 ? 1 : 0);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
282 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
283 case MAIL_SORT_DATE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
284 if (n1->seq == ctx->cache_seq && ctx->cache_type == sort_type)
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
285 time1 = ctx->cache_value;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
286 else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
287 mail_set_seq(ctx->mail, n1->seq);
6546
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
288 time1 = sort_get_date(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
289 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
290
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
291 mail_set_seq(ctx->mail, n2->seq);
6546
a53bc41fade4 Nowadays the SORT draft specifies that if Date: header is missing or broken,
Timo Sirainen <tss@iki.fi>
parents: 6532
diff changeset
292 time2 = sort_get_date(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
293
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
294 ret = time1 < time2 ? -1 :
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
295 (time1 > time2 ? 1 : 0);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
296 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
297 case MAIL_SORT_SIZE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
298 if (n1->seq == ctx->cache_seq && ctx->cache_type == sort_type)
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
299 size1 = ctx->cache_value;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
300 else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
301 mail_set_seq(ctx->mail, n1->seq);
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
302 size1 = sort_get_size(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
303 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
304
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
305 mail_set_seq(ctx->mail, n2->seq);
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
306 size2 = sort_get_size(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
307
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
308 ret = size1 < size2 ? -1 :
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
309 (size1 > size2 ? 1 : 0);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
310 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
311 case MAIL_SORT_END:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
312 return n1->seq < n2->seq ? -1 :
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
313 (n1->seq > n2->seq ? 1 : 0);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
314 case MAIL_SORT_MASK:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
315 case MAIL_SORT_FLAG_REVERSE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
316 i_unreached();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
317 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
318
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
319 if (ret == 0)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
320 return sort_node_cmp_type(ctx, sort_program+1, n1, n2);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
321
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
322 if ((*sort_program & MAIL_SORT_FLAG_REVERSE) != 0)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
323 ret = ret < 0 ? 1 : -1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
324 return ret;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
325 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
326
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
327 static int sort_node_cmp(const void *p1, const void *p2)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
328 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
329 struct sort_cmp_context *ctx = &static_node_cmp_context;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
330 const struct mail_sort_node *n1 = p1, *n2 = p2;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
331
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
332 if (n1->sort_id < n2->sort_id)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
333 return -1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
334 if (n1->sort_id > n2->sort_id)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
335 return 1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
336
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
337 return sort_node_cmp_type(ctx, ctx->program->sort_program + 1, n1, n2);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
338 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
339
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
340 static int sort_node_cmp_no_sort_id(const void *p1, const void *p2)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
341 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
342 struct sort_cmp_context *ctx = &static_node_cmp_context;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
343
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
344 return sort_node_cmp_type(ctx, ctx->program->sort_program, p1, p2);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
345 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
346
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
347 static void
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
348 index_sort_save_ids(struct mail_search_sort_program *program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
349 uint32_t first_seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
350 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
351 struct index_transaction_context *t =
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
352 (struct index_transaction_context *)program->t;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
353 const struct mail_sort_node *nodes;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
354 unsigned int i, count;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
355
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
356 nodes = array_get(&program->all_nodes, &count);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
357 for (i = 0; i < count; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
358 if (nodes[i].seq < first_seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
359 continue;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
360
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
361 i_assert(nodes[i].sort_id != 0);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
362 mail_index_update_ext(t->trans, nodes[i].seq,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
363 program->ext_id, &nodes[i].sort_id, NULL);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
364 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
365 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
366
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
367 static int
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
368 index_sort_add_ids_range(struct mail_search_sort_program *program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
369 struct mail *mail, unsigned int idx1,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
370 unsigned int idx2)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
371 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
372 struct mail_sort_node *nodes;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
373 unsigned int i, count;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
374 const char *last_str = "";
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
375 uint32_t prev_id = 0, last_id = (uint32_t)-1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
376 string_t *prev_str;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
377 const char *str;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
378 unsigned int skip;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
379 int ret = 1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
380
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
381 t_push();
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
382 nodes = array_get_modifiable(&program->all_nodes, &count);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
383 if (nodes[idx2].sort_id != 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
384 i_assert(idx1 != idx2);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
385 last_id = nodes[idx2].sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
386
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
387 last_str = sort_header_get(program->sort_program[0], mail,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
388 nodes[idx2].seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
389 idx2--;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
390 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
391
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
392 prev_str = t_str_new(256);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
393 if (nodes[idx1].sort_id != 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
394 prev_id = nodes[idx1].sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
395
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
396 str_append(prev_str,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
397 sort_header_get(program->sort_program[0], mail,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
398 nodes[idx1].seq));
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
399 idx1++;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
400 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
401
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
402 for (i = idx1; i <= idx2; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
403 str = sort_header_get(program->sort_program[0], mail,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
404 nodes[i].seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
405
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
406 if (i == idx2 && strcmp(str, last_str) == 0)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
407 nodes[i].sort_id = last_id;
6135
bc0f8a8397a3 Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents: 5336
diff changeset
408 else if (strcmp(str, str_c(prev_str)) == 0 && prev_id != 0)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
409 nodes[i].sort_id = prev_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
410 else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
411 /* divide the available space so that each message gets
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
412 an equal sized share. leave the same sized space
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
413 also between the first and the last messages */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
414 skip = (last_id - prev_id) / (idx2 - i + 2);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
415 nodes[i].sort_id = prev_id + skip;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
416 if (nodes[i].sort_id == prev_id)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
417 nodes[i].sort_id++;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
418 if (nodes[i].sort_id == last_id) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
419 /* we ran out of ID space. have to renumber
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
420 the IDs. */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
421 ret = 0;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
422 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
423 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
424
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
425 prev_id = nodes[i].sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
426 str_truncate(prev_str, 0);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
427 str_append(prev_str, str);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
428 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
429 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
430 t_pop();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
431 return ret;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
432 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
433
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
434 static void
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
435 index_sort_renumber_ids(struct mail_search_sort_program *program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
436 unsigned int idx)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
437 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
438 struct index_transaction_context *t =
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
439 (struct index_transaction_context *)program->t;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
440 struct mail_sort_node *nodes;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
441 unsigned int i, count;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
442 uint32_t sort_id, prev_sort_id, skip;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
443
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
444 nodes = array_get_modifiable(&program->all_nodes, &count);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
445 prev_sort_id = (uint32_t)-1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
446 sort_id = nodes[idx].sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
447 i_assert(sort_id == nodes[idx + 1].sort_id);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
448
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
449 if (((uint32_t)-1 - sort_id) / (count - idx + 1) < RENUMBER_SPACE) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
450 /* space is running out, lets just renumber everything */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
451 sort_id = 0;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
452 skip = (uint32_t)-1 / (count + 1);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
453 for (i = 0; i < idx; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
454 if (sort_id != prev_sort_id)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
455 sort_id += skip;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
456 prev_sort_id = nodes[i].sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
457
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
458 i_assert(sort_id != 0);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
459 nodes[i].sort_id = sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
460 mail_index_update_ext(t->trans, nodes[i].seq,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
461 program->ext_id,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
462 &nodes[i].sort_id, NULL);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
463 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
464 } else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
465 skip = RENUMBER_SPACE;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
466 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
467
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
468 for (i = idx; i < count && sort_id >= nodes[i].sort_id; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
469 if (sort_id != prev_sort_id) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
470 i_assert(sort_id <= (uint32_t)-1 - skip);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
471 sort_id += skip;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
472 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
473 prev_sort_id = nodes[i].sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
474
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
475 i_assert(sort_id != 0);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
476 if (nodes[i].sort_id != 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
477 nodes[i].sort_id = sort_id;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
478 mail_index_update_ext(t->trans, nodes[i].seq,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
479 program->ext_id,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
480 &nodes[i].sort_id, NULL);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
481 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
482 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
483 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
484
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
485 static void
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
486 index_sort_add_ids(struct mail_search_sort_program *program, struct mail *mail)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
487 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
488 const struct mail_sort_node *nodes;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
489 unsigned int i, j, count;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
490
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
491 nodes = array_get(&program->all_nodes, &count);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
492 for (i = 0; i < count; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
493 if (nodes[i].sort_id == 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
494 for (j = i + 1; j < count; j++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
495 if (nodes[j].sort_id != 0)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
496 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
497 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
498 if (index_sort_add_ids_range(program, mail,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
499 i == 0 ? 0 : i-1,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
500 I_MIN(j, count-1)) == 0)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
501 index_sort_renumber_ids(program, i);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
502 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
503 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
504 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
505
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
506 static void index_sort_preset_sort_ids(struct mail_search_sort_program *program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
507 uint32_t last_seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
508 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
509 struct mail_sort_node node;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
510 struct mail *mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
511 uint32_t (*get_sort_id)(struct mail *);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
512
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
513 switch (program->sort_program[0] & MAIL_SORT_MASK) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
514 case MAIL_SORT_ARRIVAL:
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
515 get_sort_id = sort_get_arrival;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
516 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
517 case MAIL_SORT_DATE:
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
518 get_sort_id = sort_get_date;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
519 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
520 case MAIL_SORT_SIZE:
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
521 get_sort_id = sort_get_size;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
522 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
523 default:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
524 i_unreached();
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
525 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
526
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
527 /* add the missing nodes with their sort_ids */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
528 mail = program->temp_mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
529 node.seq = array_count(&program->all_nodes) + 1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
530 for (; node.seq <= last_seq; node.seq++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
531 mail_set_seq(mail, node.seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
532 node.sort_id = get_sort_id(mail);
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
533 i_assert(node.sort_id != 0);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
534 array_append(&program->all_nodes, &node, 1);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
535 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
536
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
537 /* @UNSAFE: and sort them */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
538 memset(&static_node_cmp_context, 0, sizeof(static_node_cmp_context));
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
539 static_node_cmp_context.program = program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
540 static_node_cmp_context.mail = mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
541
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
542 qsort(array_idx_modifiable(&program->all_nodes, 0), last_seq,
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
543 sizeof(struct mail_sort_node), sort_node_cmp);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
544 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
545
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
546 static void index_sort_cache_seq(struct sort_cmp_context *ctx,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
547 enum mail_sort_type sort_type, uint32_t seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
548 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
549 ctx->cache_seq = seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
550 ctx->cache_type = sort_type & MAIL_SORT_MASK;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
551
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
552 mail_set_seq(ctx->mail, seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
553 switch (ctx->cache_type) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
554 case MAIL_SORT_ARRIVAL:
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
555 ctx->cache_value = sort_get_arrival(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
556 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
557 case MAIL_SORT_DATE:
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
558 ctx->cache_value = sort_get_date(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
559 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
560 case MAIL_SORT_SIZE:
6547
7a207cbc008b Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents: 6546
diff changeset
561 ctx->cache_value = sort_get_size(ctx->mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
562 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
563 default:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
564 ctx->cache_str = sort_header_get(sort_type, ctx->mail, seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
565 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
566 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
567 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
568
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
569 static void index_sort_headers(struct mail_search_sort_program *program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
570 uint32_t last_seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
571 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
572 struct mail_sort_node *nodes, node;
5336
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
573 const struct mail_sort_node *cnodes;
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
574 unsigned int count, idx;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
575
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
576 /* we wish to avoid reading the actual headers as much as possible.
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
577 first sort the nodes which already have sort_ids, then start
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
578 inserting the new nodes by finding their insertion position with
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
579 binary search */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
580 memset(&static_node_cmp_context, 0, sizeof(static_node_cmp_context));
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
581 static_node_cmp_context.program = program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
582 static_node_cmp_context.mail = program->temp_mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
583
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
584 /* @UNSAFE */
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
585 nodes = array_get_modifiable(&program->all_nodes, &count);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
586 if (program->last_sorted_seq != count) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
587 qsort(nodes, count, sizeof(struct mail_sort_node),
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
588 sort_node_cmp);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
589 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
590
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
591 node.sort_id = 0;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
592 for (node.seq = count + 1; node.seq <= last_seq; node.seq++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
593 index_sort_cache_seq(&static_node_cmp_context,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
594 program->sort_program[0], node.seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
595
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4303
diff changeset
596 cnodes = array_get_modifiable(&program->nodes, &count);
5336
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
597 bsearch_insert_pos(&node, cnodes, count, sizeof(*cnodes),
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
598 sort_node_cmp_no_sort_id,
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
599 &idx);
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
600 array_insert(&program->nodes, idx, &node, 1);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
601 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
602
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
603 index_sort_add_ids(program, static_node_cmp_context.mail);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
604 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
605
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
606 static void index_sort_build(struct mail_search_sort_program *program,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
607 uint32_t last_seq)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
608 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
609 struct index_mailbox *ibox = (struct index_mailbox *)program->t->box;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
610 struct mail_sort_node node;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
611 const void *data;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
612 unsigned int i, first_missing_sort_id_seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
613
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
614 i = array_count(&program->all_nodes);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
615 if (i == 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
616 /* we're building the array from scratch. add here only the
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
617 messages that have sort_ids set. */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
618 program->last_sorted_seq = 0;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
619 for (; i < last_seq; i++) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
620 node.seq = i+1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
621
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
622 mail_index_lookup_ext(ibox->view, i+1, program->ext_id,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
623 &data, NULL);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
624
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
625 node.sort_id = data == NULL ? 0 :
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
626 *(const uint32_t *)data;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
627 if (node.sort_id == 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
628 /* the rest don't have sort_ids either */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
629 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
630 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
631 array_append(&program->all_nodes, &node, 1);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
632 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
633 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
634 first_missing_sort_id_seq = i + 1;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
635
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
636 switch (program->sort_program[0] & MAIL_SORT_MASK) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
637 case MAIL_SORT_ARRIVAL:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
638 case MAIL_SORT_DATE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
639 case MAIL_SORT_SIZE:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
640 index_sort_preset_sort_ids(program, last_seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
641 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
642 default:
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
643 index_sort_headers(program, last_seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
644 break;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
645 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
646 index_sort_save_ids(program, first_missing_sort_id_seq);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
647 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
648
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
649 static void index_sort_add_node(struct mail_search_sort_program *program,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
650 const struct mail_sort_node *node)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
651 {
5336
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
652 const struct mail_sort_node *nodes;
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
653 unsigned int count, idx;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
654
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
655 memset(&static_node_cmp_context, 0, sizeof(static_node_cmp_context));
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
656 static_node_cmp_context.program = program;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
657 static_node_cmp_context.mail = program->temp_mail;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
658
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
659 nodes = array_get(&program->nodes, &count);
5336
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
660 bsearch_insert_pos(node, nodes, count,
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
661 sizeof(*node), sort_node_cmp,
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
662 &idx);
109ca861405f bsearch_insert_pos() API changed. Patch by Max Kellermann
Timo Sirainen <tss@iki.fi>
parents: 4935
diff changeset
663 array_insert(&program->nodes, idx, node, 1);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
664
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
665 program->last_sorted_seq = node->seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
666 program->prev_seq = node->seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
667 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
668
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
669 void index_sort_list_add(struct mail_search_sort_program *program,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
670 struct mail *mail)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
671 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
672 struct index_transaction_context *t =
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
673 (struct index_transaction_context *)program->t;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
674 const struct mail_index_header *hdr;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
675 const void *data;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
676 struct mail_sort_node node;
6532
da3093d9f572 Assert-crashfix
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
677 uint32_t last_seq;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
678
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
679 i_assert(mail->transaction == program->t);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
680
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
681 if (program->prev_seq + 1 != mail->seq)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
682 program->skipped_mails = TRUE;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
683
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
684 node.seq = mail->seq;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
685 if (program->last_sorted_seq == program->prev_seq) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
686 /* we're still on the fast path using sort_ids from the
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
687 index file */
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
688 mail_index_lookup_ext(t->trans_view, mail->seq,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
689 program->ext_id, &data, NULL);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
690 node.sort_id = data == NULL ? 0 : *(const uint32_t *)data;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
691 if (node.sort_id != 0) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
692 index_sort_add_node(program, &node);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
693 return;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
694 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
695 i_assert(!program->sort_ids_added);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
696 } else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
697 node.sort_id = 0;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
698 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
699
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
700 /* sort_ids are missing, have to generate them */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
701 if (!program->skipped_mails) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
702 /* as long as we think we're returning all the mails sorted,
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
703 which is the common case, we want to avoid duplicating the
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
704 node array. so here we just keep counting the sequences
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
705 until either we skip a sequence or we reach list_finish() */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
706 program->prev_seq = mail->seq;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
707 return;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
708 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
709
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
710 /* we're not returning all the mails. have to create a temporary array
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
711 for all the nodes so we can set all the missing sort_ids. */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
712 hdr = mail_index_get_header(t->ibox->view);
4596
bf4e98a0de3f Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents: 4594
diff changeset
713 i_array_init(&program->all_nodes, hdr->messages_count);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
714 index_sort_build(program, hdr->messages_count);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
715 array_free(&program->all_nodes);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
716
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
717 /* add the nodes in the middle */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
718 node.seq = program->last_sorted_seq + 1;
6532
da3093d9f572 Assert-crashfix
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
719 last_seq = program->prev_seq;
da3093d9f572 Assert-crashfix
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
720 for (; node.seq <= last_seq; node.seq++) {
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
721 mail_index_lookup_ext(t->trans_view, mail->seq, program->ext_id,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
722 &data, NULL);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
723
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
724 node.sort_id = *(const uint32_t *)data;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
725 i_assert(node.sort_id != 0);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
726
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
727 index_sort_add_node(program, &node);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
728 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
729
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
730 /* and add this last node */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
731 program->sort_ids_added = TRUE;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
732 index_sort_list_add(program, mail);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
733 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
734
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
735 void index_sort_list_finish(struct mail_search_sort_program *program)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
736 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
737 if (program->last_sorted_seq != program->prev_seq) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
738 /* nodes array contains a contiguous range of sequences from
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
739 the beginning, with the last ones missing sort_id. we can
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
740 just sort the array directly without copying it. */
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
741 i_assert(!program->sort_ids_added);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
742
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
743 program->all_nodes = program->nodes;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
744 index_sort_build(program, program->prev_seq);
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
745 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
746
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
747 program->nodes_ptr =
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
748 array_get(&program->nodes, &program->nodes_count);
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
749
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
750 if (program->reverse)
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
751 program->iter_idx = program->nodes_count;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
752 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
753
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
754 bool index_sort_list_next(struct mail_search_sort_program *program,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
755 struct mail *mail)
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
756 {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
757 const struct mail_sort_node *node;
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
758
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
759 if (!program->reverse) {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
760 if (program->iter_idx == program->nodes_count)
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
761 return FALSE;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
762
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
763 node = &program->nodes_ptr[program->iter_idx++];
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
764 } else {
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
765 if (program->iter_idx == 0)
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
766 return FALSE;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
767
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
768 node = &program->nodes_ptr[--program->iter_idx];
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
769 }
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
770 mail_set_seq(mail, node->seq);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6136
diff changeset
771 return TRUE;
4303
5f03738219a6 Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff changeset
772 }