From: Marco Bettini Date: Wed, 8 Jun 2022 10:05:09 +0000 (+0000) Subject: indexer: indexer_queue_append_request() - Reorganize the code for better readability X-Git-Tag: 2.4.0~3982 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2507dccfbd1acdaa962c2fa2022bb4a095bfd45a;p=thirdparty%2Fdovecot%2Fcore.git indexer: indexer_queue_append_request() - Reorganize the code for better readability Isolate the section handling duplicated entries from the part creating creating new ones. --- diff --git a/src/indexer/indexer-queue.c b/src/indexer/indexer-queue.c index c3392ca221..5df538bc78 100644 --- a/src/indexer/indexer-queue.c +++ b/src/indexer/indexer-queue.c @@ -103,15 +103,7 @@ indexer_queue_append_request(struct indexer_queue *queue, bool append, char *first_username; request = indexer_queue_lookup(queue, username, mailbox); - if (request == NULL) { - request = i_new(struct indexer_request, 1); - request->username = i_strdup(username); - request->mailbox = i_strdup(mailbox); - request->session_id = i_strdup(session_id); - request->max_recent_msgs = max_recent_msgs; - request_add_context(request, context); - hash_table_insert(queue->requests, request, request); - } else { + if (request != NULL) { if (request->max_recent_msgs > max_recent_msgs) request->max_recent_msgs = max_recent_msgs; request_add_context(request, context); @@ -121,18 +113,26 @@ indexer_queue_append_request(struct indexer_queue *queue, bool append, request->reindex_tail = TRUE; else request->reindex_head = TRUE; - return request; - } - if (append) { - /* keep the request in its old position */ - return request; + } else { + if (append) { + /* keep the request in its old position */ + } else { + /* move request to beginning of the queue */ + DLLIST2_REMOVE(&queue->head, &queue->tail, request); + DLLIST2_PREPEND(&queue->head, &queue->tail, request); + } } - /* move request to beginning of the queue */ - DLLIST2_REMOVE(&queue->head, &queue->tail, request); - DLLIST2_PREPEND(&queue->head, &queue->tail, request); return request; } + request = i_new(struct indexer_request, 1); + request->username = i_strdup(username); + request->mailbox = i_strdup(mailbox); + request->session_id = i_strdup(session_id); + request->max_recent_msgs = max_recent_msgs; + request_add_context(request, context); + hash_table_insert(queue->requests, request, request); + if (!hash_table_lookup_full(queue->users, username, &first_username, &first_request)) { first_username = i_strdup(username);