Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/index-sort.c @ 8006:0a3b5ddb0869 HEAD
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 13 Jul 2008 19:09:55 +0300 |
parents | 439636cce455 |
children | b9faf4db2a9f |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
7043
diff
changeset
|
1 /* Copyright (c) 2006-2008 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 #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
|
4 #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
|
5 #include "str.h" |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
6 #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
|
7 #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
|
8 #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
|
9 #include "index-storage.h" |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
10 #include "index-sort-private.h" |
4303
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 #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
|
13 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
14 struct mail_sort_node_date { |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
15 uint32_t seq; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
16 time_t date; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
17 }; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
18 ARRAY_DEFINE_TYPE(mail_sort_node_date, struct mail_sort_node_date); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
19 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
20 struct mail_sort_node_size { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
21 uint32_t seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
22 uoff_t size; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
23 }; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
24 ARRAY_DEFINE_TYPE(mail_sort_node_size, struct mail_sort_node_size); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
25 |
8006
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
26 struct mail_sort_node_float { |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
27 uint32_t seq; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
28 float num; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
29 }; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
30 ARRAY_DEFINE_TYPE(mail_sort_node_float, struct mail_sort_node_float); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
31 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
32 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
|
33 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
|
34 struct mail *mail; |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
35 bool reverse; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
36 }; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
37 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
38 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
|
39 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
40 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
41 index_sort_list_add_arrival(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
42 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
43 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
44 ARRAY_TYPE(mail_sort_node_date) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
45 struct mail_sort_node_date *node; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
46 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
47 node = array_append_space(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
48 node->seq = mail->seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
49 if (mail_get_received_date(mail, &node->date) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
50 node->date = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
51 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
52 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
53 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
54 index_sort_list_add_date(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
55 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
56 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
57 ARRAY_TYPE(mail_sort_node_date) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
58 struct mail_sort_node_date *node; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
59 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
60 node = array_append_space(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
61 node->seq = mail->seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
62 if (mail_get_date(mail, &node->date, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
63 node->date = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
64 else if (node->date == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
65 if (mail_get_received_date(mail, &node->date) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
66 node->date = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
67 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
68 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
69 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
70 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
71 index_sort_list_add_size(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
72 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
73 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
74 ARRAY_TYPE(mail_sort_node_size) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
75 struct mail_sort_node_size *node; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
76 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
77 node = array_append_space(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
78 node->seq = mail->seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
79 if (mail_get_virtual_size(mail, &node->size) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
80 node->size = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
81 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
82 |
8006
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
83 static float index_sort_get_score(struct mail *mail) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
84 { |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
85 const char *str; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
86 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
87 if (mail_get_special(mail, MAIL_FETCH_SEARCH_SCORE, &str) < 0) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
88 return 0; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
89 else |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
90 return strtod(str, NULL); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
91 } |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
92 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
93 static void |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
94 index_sort_list_add_score(struct mail_search_sort_program *program, |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
95 struct mail *mail) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
96 { |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
97 ARRAY_TYPE(mail_sort_node_float) *nodes = program->context; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
98 struct mail_sort_node_float *node; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
99 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
100 node = array_append_space(nodes); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
101 node->seq = mail->seq; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
102 node->num = index_sort_get_score(mail); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
103 } |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
104 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
105 void index_sort_list_add(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
106 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
107 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
108 i_assert(mail->transaction == program->t); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
109 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
110 program->sort_list_add(program, mail); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
111 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
112 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
113 static int sort_node_date_cmp(const void *p1, const void *p2) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
114 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
115 struct sort_cmp_context *ctx = &static_node_cmp_context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
116 const struct mail_sort_node_date *n1 = p1, *n2 = p2; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
117 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
118 if (n1->date < n2->date) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
119 return !ctx->reverse ? -1 : 1; |
7855
b5a6e6783786
Message sorting by date, arrival or size was broken.
Timo Sirainen <tss@iki.fi>
parents:
7564
diff
changeset
|
120 if (n1->date > n2->date) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
121 return !ctx->reverse ? 1 : -1; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
122 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
123 return index_sort_node_cmp_type(ctx->mail, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
124 ctx->program->sort_program + 1, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
125 n1->seq, n2->seq); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
126 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
127 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
128 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
129 index_sort_list_finish_date(struct mail_search_sort_program *program) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
130 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
131 ARRAY_TYPE(mail_sort_node_date) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
132 struct mail_sort_node_date *date_nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
133 unsigned int count; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
134 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
135 date_nodes = array_get_modifiable(nodes, &count); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
136 qsort(date_nodes, count, sizeof(struct mail_sort_node_date), |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
137 sort_node_date_cmp); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
138 memcpy(&program->seqs, nodes, sizeof(program->seqs)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
139 i_free(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
140 program->context = NULL; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
141 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
142 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
143 static int sort_node_size_cmp(const void *p1, const void *p2) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
144 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
145 struct sort_cmp_context *ctx = &static_node_cmp_context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
146 const struct mail_sort_node_size *n1 = p1, *n2 = p2; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
147 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
148 if (n1->size < n2->size) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
149 return !ctx->reverse ? -1 : 1; |
7855
b5a6e6783786
Message sorting by date, arrival or size was broken.
Timo Sirainen <tss@iki.fi>
parents:
7564
diff
changeset
|
150 if (n1->size > n2->size) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
151 return !ctx->reverse ? 1 : -1; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
152 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
153 return index_sort_node_cmp_type(ctx->mail, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
154 ctx->program->sort_program + 1, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
155 n1->seq, n2->seq); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
156 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
157 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
158 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
159 index_sort_list_finish_size(struct mail_search_sort_program *program) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
160 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
161 ARRAY_TYPE(mail_sort_node_size) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
162 struct mail_sort_node_size *size_nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
163 unsigned int count; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
164 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
165 size_nodes = array_get_modifiable(nodes, &count); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
166 qsort(size_nodes, count, sizeof(struct mail_sort_node_size), |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
167 sort_node_size_cmp); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
168 memcpy(&program->seqs, nodes, sizeof(program->seqs)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
169 i_free(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
170 program->context = NULL; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
171 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
172 |
8006
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
173 static int sort_node_float_cmp(const void *p1, const void *p2) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
174 { |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
175 struct sort_cmp_context *ctx = &static_node_cmp_context; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
176 const struct mail_sort_node_float *n1 = p1, *n2 = p2; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
177 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
178 if (n1->num < n2->num) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
179 return !ctx->reverse ? -1 : 1; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
180 if (n1->num > n2->num) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
181 return !ctx->reverse ? 1 : -1; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
182 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
183 return index_sort_node_cmp_type(ctx->mail, |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
184 ctx->program->sort_program + 1, |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
185 n1->seq, n2->seq); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
186 } |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
187 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
188 static void |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
189 index_sort_list_finish_float(struct mail_search_sort_program *program) |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
190 { |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
191 ARRAY_TYPE(mail_sort_node_float) *nodes = program->context; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
192 struct mail_sort_node_float *float_nodes; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
193 unsigned int count; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
194 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
195 float_nodes = array_get_modifiable(nodes, &count); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
196 qsort(float_nodes, count, sizeof(struct mail_sort_node_float), |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
197 sort_node_float_cmp); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
198 memcpy(&program->seqs, nodes, sizeof(program->seqs)); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
199 i_free(nodes); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
200 program->context = NULL; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
201 } |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
202 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
203 void index_sort_list_finish(struct mail_search_sort_program *program) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
204 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
205 memset(&static_node_cmp_context, 0, sizeof(static_node_cmp_context)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
206 static_node_cmp_context.program = program; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
207 static_node_cmp_context.mail = program->temp_mail; |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
208 static_node_cmp_context.reverse = |
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
209 (program->sort_program[0] & MAIL_SORT_FLAG_REVERSE) != 0; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
210 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
211 program->sort_list_finish(program); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
212 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
213 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
214 bool index_sort_list_next(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
215 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
216 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
217 const uint32_t *seqp; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
218 |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
219 if (program->iter_idx == array_count(&program->seqs)) |
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
220 return FALSE; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
221 |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
222 seqp = array_idx(&program->seqs, program->iter_idx++); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
223 mail_set_seq(mail, *seqp); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
224 return TRUE; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
225 } |
6970
891d2b36feee
Don't add arrival/date/size sort IDs to index file. They can be looked up
Timo Sirainen <tss@iki.fi>
parents:
6969
diff
changeset
|
226 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
231 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
|
232 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
|
233 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
234 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
|
235 return NULL; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
236 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
237 /* 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
|
238 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
|
239 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
|
240 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
|
241 |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
242 for (i = 0; i < MAX_SORT_PROGRAM_SIZE; i++) { |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
243 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
|
244 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
|
245 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
246 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
247 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
|
248 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
|
249 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
250 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
|
251 case MAIL_SORT_ARRIVAL: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
252 case MAIL_SORT_DATE: { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
253 ARRAY_TYPE(mail_sort_node_date) *nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
254 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
255 nodes = i_malloc(sizeof(*nodes)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
256 i_array_init(nodes, 128); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
257 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
258 if ((program->sort_program[0] & |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
259 MAIL_SORT_MASK) == MAIL_SORT_ARRIVAL) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
260 program->sort_list_add = index_sort_list_add_arrival; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
261 else |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
262 program->sort_list_add = index_sort_list_add_date; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
263 program->sort_list_finish = index_sort_list_finish_date; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
264 program->context = nodes; |
6970
891d2b36feee
Don't add arrival/date/size sort IDs to index file. They can be looked up
Timo Sirainen <tss@iki.fi>
parents:
6969
diff
changeset
|
265 break; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
266 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
267 case MAIL_SORT_SIZE: { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
268 ARRAY_TYPE(mail_sort_node_size) *nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
269 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
270 nodes = i_malloc(sizeof(*nodes)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
271 i_array_init(nodes, 128); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
272 program->sort_list_add = index_sort_list_add_size; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
273 program->sort_list_finish = index_sort_list_finish_size; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
274 program->context = nodes; |
6970
891d2b36feee
Don't add arrival/date/size sort IDs to index file. They can be looked up
Timo Sirainen <tss@iki.fi>
parents:
6969
diff
changeset
|
275 break; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
276 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 case MAIL_SORT_TO: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
281 program->sort_list_add = index_sort_list_add_string; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
282 program->sort_list_finish = index_sort_list_finish_string; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
283 index_sort_list_init_string(program); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
284 break; |
8006
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
285 case MAIL_SORT_SEARCH_SCORE: { |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
286 ARRAY_TYPE(mail_sort_node_float) *nodes; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
287 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
288 nodes = i_malloc(sizeof(*nodes)); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
289 i_array_init(nodes, 128); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
290 program->sort_list_add = index_sort_list_add_score; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
291 program->sort_list_finish = index_sort_list_finish_float; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
292 program->context = nodes; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
293 break; |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
294 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
295 default: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
296 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
297 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
298 return program; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
299 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
300 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
301 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
|
302 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
303 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
|
304 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
305 *_program = NULL; |
7956 | 306 |
307 if (program->context != NULL) | |
308 index_sort_list_finish(program); | |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
309 mail_free(&program->temp_mail); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
310 array_free(&program->seqs); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
311 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
|
312 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
313 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
314 static int |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
315 get_first_mailbox(struct mail *mail, const char *header, const char **mailbox_r) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
316 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
317 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
|
318 const char *str; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
319 int ret; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
320 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
321 if ((ret = mail_get_first_header_utf8(mail, header, &str)) <= 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
322 *mailbox_r = ""; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
323 return ret; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
324 } |
4303
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 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
|
327 (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
|
328 strlen(str), 1, TRUE); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
329 *mailbox_r = addr != NULL ? addr->mailbox : ""; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
330 return 0; |
4303
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 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
333 int index_sort_header_get(struct mail *mail, uint32_t seq, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
334 enum mail_sort_type sort_type, string_t *dest) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
335 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
336 const char *str; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
337 int ret; |
4303
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 mail_set_seq(mail, seq); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
340 str_truncate(dest, 0); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
341 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
342 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
|
343 case MAIL_SORT_SUBJECT: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
344 if ((ret = mail_get_first_header(mail, "Subject", &str)) <= 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
345 return ret; |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
346 str = imap_get_base_subject_cased(pool_datastack_create(), |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
347 str, NULL); |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
348 str_append(dest, str); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
349 return 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
350 case MAIL_SORT_CC: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
351 ret = get_first_mailbox(mail, "Cc", &str); |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
352 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
353 case MAIL_SORT_FROM: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
354 ret = get_first_mailbox(mail, "From", &str); |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
355 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
356 case MAIL_SORT_TO: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
357 ret = get_first_mailbox(mail, "To", &str); |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
358 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
359 default: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
360 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
361 } |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
362 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
363 (void)uni_utf8_to_decomposed_titlecase(str, (size_t)-1, dest); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
364 return ret; |
6547
7a207cbc008b
Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents:
6546
diff
changeset
|
365 } |
7a207cbc008b
Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents:
6546
diff
changeset
|
366 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
367 int index_sort_node_cmp_type(struct mail *mail, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
368 const enum mail_sort_type *sort_program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
369 uint32_t seq1, uint32_t seq2) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
370 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
371 enum mail_sort_type sort_type; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
372 time_t time1, time2; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
373 uoff_t size1, size2; |
8006
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
374 float float1, float2; |
4935 | 375 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
|
376 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 case MAIL_SORT_SUBJECT: |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7201
diff
changeset
|
383 T_BEGIN { |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
384 string_t *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
|
385 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
386 str1 = t_str_new(256); |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
387 str2 = t_str_new(256); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
388 index_sort_header_get(mail, seq1, sort_type, str1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
389 index_sort_header_get(mail, seq2, sort_type, str2); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6711
diff
changeset
|
390 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
391 ret = strcmp(str_c(str1), str_c(str2)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7201
diff
changeset
|
392 } T_END; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
393 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
394 case MAIL_SORT_ARRIVAL: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
395 mail_set_seq(mail, seq1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
396 if (mail_get_received_date(mail, &time1) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
397 time1 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
398 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
399 mail_set_seq(mail, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
400 if (mail_get_received_date(mail, &time2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
401 time1 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
402 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
403 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
|
404 (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
|
405 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
406 case MAIL_SORT_DATE: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
407 mail_set_seq(mail, seq1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
408 if (mail_get_date(mail, &time1, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
409 time1 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
410 else if (time1 == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
411 if (mail_get_received_date(mail, &time1) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
412 time1 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
413 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
414 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
415 mail_set_seq(mail, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
416 if (mail_get_date(mail, &time2, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
417 time2 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
418 else if (time2 == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
419 if (mail_get_received_date(mail, &time2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
420 time2 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
421 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
422 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
423 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
|
424 (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
|
425 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
426 case MAIL_SORT_SIZE: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
427 mail_set_seq(mail, seq1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
428 if (mail_get_virtual_size(mail, &size1) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
429 size1 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
430 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
431 mail_set_seq(mail, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
432 if (mail_get_virtual_size(mail, &size2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
433 size2 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
434 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
435 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
|
436 (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
|
437 break; |
8006
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
438 case MAIL_SORT_SEARCH_SCORE: |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
439 mail_set_seq(mail, seq1); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
440 float1 = index_sort_get_score(mail); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
441 mail_set_seq(mail, seq2); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
442 float2 = index_sort_get_score(mail); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
443 |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
444 ret = float1 < float2 ? -1 : |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
445 (float1 > float2 ? 1 : 0); |
0a3b5ddb0869
Added support for sorting by X-SCORE. Currently it's only set by fts-solr.
Timo Sirainen <tss@iki.fi>
parents:
7956
diff
changeset
|
446 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
447 case MAIL_SORT_END: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
448 return seq1 < seq2 ? -1 : |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
449 (seq1 > seq2 ? 1 : 0); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
450 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
|
451 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
|
452 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
453 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
454 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
455 if (ret == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
456 return index_sort_node_cmp_type(mail, sort_program+1, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
457 seq1, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
458 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
459 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
460 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
|
461 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
|
462 return ret; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
463 } |