Mercurial > dovecot > core-2.2
comparison src/lib-storage/index/index-search.c @ 12611:16a541057e88
lib-storage: Moved setting "wanted fields/headers" fields for sort program from imap-specific code.
Also separate between fields that are actually wanted to be fetched from the
fields that sorting wants to temporarily use.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 31 Jan 2011 02:13:06 +0200 |
parents | b96efbad2fa4 |
children | 447bce266022 |
comparison
equal
deleted
inserted
replaced
12610:4964b39c6ae4 | 12611:16a541057e88 |
---|---|
1038 } | 1038 } |
1039 } | 1039 } |
1040 return ret; | 1040 return ret; |
1041 } | 1041 } |
1042 | 1042 |
1043 static void | |
1044 wanted_sort_fields_get(struct mailbox *box, | |
1045 const enum mail_sort_type *sort_program, | |
1046 enum mail_fetch_field *wanted_fields_r, | |
1047 struct mailbox_header_lookup_ctx **headers_ctx_r) | |
1048 { | |
1049 const char *headers[2]; | |
1050 | |
1051 *wanted_fields_r = 0; | |
1052 *headers_ctx_r = NULL; | |
1053 | |
1054 headers[0] = headers[1] = NULL; | |
1055 switch (sort_program[0] & MAIL_SORT_MASK) { | |
1056 case MAIL_SORT_ARRIVAL: | |
1057 *wanted_fields_r = MAIL_FETCH_RECEIVED_DATE; | |
1058 break; | |
1059 case MAIL_SORT_CC: | |
1060 headers[0] = "Cc"; | |
1061 break; | |
1062 case MAIL_SORT_DATE: | |
1063 *wanted_fields_r = MAIL_FETCH_DATE; | |
1064 break; | |
1065 case MAIL_SORT_FROM: | |
1066 headers[0] = "From"; | |
1067 break; | |
1068 case MAIL_SORT_SIZE: | |
1069 *wanted_fields_r = MAIL_FETCH_VIRTUAL_SIZE; | |
1070 break; | |
1071 case MAIL_SORT_SUBJECT: | |
1072 headers[0] = "Subject"; | |
1073 break; | |
1074 case MAIL_SORT_TO: | |
1075 headers[0] = "To"; | |
1076 break; | |
1077 } | |
1078 | |
1079 if (headers[0] != NULL) | |
1080 *headers_ctx_r = mailbox_header_lookup_init(box, headers); | |
1081 } | |
1082 | |
1043 void index_storage_search_init_context(struct index_search_context *ctx, | 1083 void index_storage_search_init_context(struct index_search_context *ctx, |
1044 struct mailbox_transaction_context *t, | 1084 struct mailbox_transaction_context *t, |
1045 struct mail_search_args *args, | 1085 struct mail_search_args *args, |
1046 const enum mail_sort_type *sort_program) | 1086 const enum mail_sort_type *sort_program) |
1047 { | 1087 { |
1069 ctx->failed = TRUE; | 1109 ctx->failed = TRUE; |
1070 if (search_build_inthreads(ctx, args->args) < 0) | 1110 if (search_build_inthreads(ctx, args->args) < 0) |
1071 ctx->failed = TRUE; | 1111 ctx->failed = TRUE; |
1072 } | 1112 } |
1073 | 1113 |
1114 if (sort_program != NULL) { | |
1115 wanted_sort_fields_get(ctx->box, sort_program, | |
1116 &ctx->extra_wanted_fields, | |
1117 &ctx->extra_wanted_headers); | |
1118 } | |
1119 | |
1074 search_get_seqset(ctx, status.messages, args->args); | 1120 search_get_seqset(ctx, status.messages, args->args); |
1075 (void)mail_search_args_foreach(args->args, search_init_arg, ctx); | 1121 (void)mail_search_args_foreach(args->args, search_init_arg, ctx); |
1076 | 1122 |
1077 /* Need to reset results for match_always cases */ | 1123 /* Need to reset results for match_always cases */ |
1078 mail_search_args_reset(ctx->mail_ctx.args->args, FALSE); | 1124 mail_search_args_reset(ctx->mail_ctx.args->args, FALSE); |
1115 | 1161 |
1116 mail_search_args_reset(ctx->mail_ctx.args->args, FALSE); | 1162 mail_search_args_reset(ctx->mail_ctx.args->args, FALSE); |
1117 (void)mail_search_args_foreach(ctx->mail_ctx.args->args, | 1163 (void)mail_search_args_foreach(ctx->mail_ctx.args->args, |
1118 search_arg_deinit, NULL); | 1164 search_arg_deinit, NULL); |
1119 | 1165 |
1166 if (ctx->extra_wanted_headers != NULL) | |
1167 mailbox_header_lookup_unref(&ctx->extra_wanted_headers); | |
1120 if (ctx->mail_ctx.sort_program != NULL) | 1168 if (ctx->mail_ctx.sort_program != NULL) |
1121 index_sort_program_deinit(&ctx->mail_ctx.sort_program); | 1169 index_sort_program_deinit(&ctx->mail_ctx.sort_program); |
1122 if (ctx->thread_ctx != NULL) | 1170 if (ctx->thread_ctx != NULL) |
1123 mail_thread_deinit(&ctx->thread_ctx); | 1171 mail_thread_deinit(&ctx->thread_ctx); |
1124 array_free(&ctx->mail_ctx.results); | 1172 array_free(&ctx->mail_ctx.results); |
1345 *tryagain_r = TRUE; | 1393 *tryagain_r = TRUE; |
1346 return FALSE; | 1394 return FALSE; |
1347 } | 1395 } |
1348 | 1396 |
1349 ctx->mail = mail; | 1397 ctx->mail = mail; |
1398 mail_private->extra_wanted_fields = ctx->extra_wanted_fields; | |
1399 mail_private->extra_wanted_headers = ctx->extra_wanted_headers; | |
1350 | 1400 |
1351 if (ioloop_time - ctx->last_notify.tv_sec >= | 1401 if (ioloop_time - ctx->last_notify.tv_sec >= |
1352 SEARCH_NOTIFY_INTERVAL_SECS) | 1402 SEARCH_NOTIFY_INTERVAL_SECS) |
1353 index_storage_search_notify(box, ctx); | 1403 index_storage_search_notify(box, ctx); |
1354 | 1404 |
1394 } | 1444 } |
1395 } | 1445 } |
1396 ctx->mail = NULL; | 1446 ctx->mail = NULL; |
1397 ctx->imail = NULL; | 1447 ctx->imail = NULL; |
1398 mail_private->stats_track = old_stats_track; | 1448 mail_private->stats_track = old_stats_track; |
1449 mail_private->extra_wanted_fields = 0; | |
1450 mail_private->extra_wanted_headers = NULL; | |
1399 | 1451 |
1400 if (!match && _ctx->sort_program != NULL && | 1452 if (!match && _ctx->sort_program != NULL && |
1401 !*tryagain_r && !ctx->failed) { | 1453 !*tryagain_r && !ctx->failed) { |
1402 /* finished searching the messages. now sort them and start | 1454 /* finished searching the messages. now sort them and start |
1403 returning the messages. */ | 1455 returning the messages. */ |