]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
plugins/fts: fts-indexer - Move fts_indexer_init to end of file
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 31 May 2021 16:31:35 +0000 (19:31 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 14 Jun 2021 14:56:40 +0000 (17:56 +0300)
Simplifies next commit

src/plugins/fts/fts-indexer.c

index 6ffd95574111b47fb8942d8a92658471e1e9d2db..293ab72124a89801ef70d420f8dad6edb865ebc2 100644 (file)
@@ -89,57 +89,6 @@ static void fts_indexer_notify(struct fts_indexer_context *ctx)
        } T_END;
 }
 
-int fts_indexer_init(struct fts_backend *backend, struct mailbox *box,
-                    struct fts_indexer_context **ctx_r)
-{
-       struct fts_indexer_context *ctx;
-       struct mailbox_status status;
-       uint32_t last_uid, seq1, seq2;
-       const char *path, *cmd, *value, *error;
-       int fd;
-
-       if (fts_backend_get_last_uid(backend, box, &last_uid) < 0)
-               return -1;
-
-       mailbox_get_open_status(box, STATUS_UIDNEXT, &status);
-       if (status.uidnext == last_uid+1) {
-               /* everything is already indexed */
-               return 0;
-       }
-
-       mailbox_get_seq_range(box, last_uid+1, (uint32_t)-1, &seq1, &seq2);
-       if (seq1 == 0) {
-               /* no new messages (last messages in mailbox were expunged) */
-               return 0;
-       }
-
-       cmd = t_strdup_printf("PREPEND\t1\t%s\t%s\t0\t%s\n",
-                             str_tabescape(box->storage->user->username),
-                             str_tabescape(box->vname),
-                             str_tabescape(box->storage->user->session_id));
-       fd = fts_indexer_cmd(box->storage->user, cmd, &path);
-       if (fd == -1)
-               return -1;
-
-       /* connect to indexer and request immediate indexing of the mailbox */
-       ctx = i_new(struct fts_indexer_context, 1);
-       ctx->box = box;
-       ctx->conn.label = i_strdup(path);
-       ctx->conn.fd_in = fd;
-       ctx->conn.input = i_stream_create_fd(fd, 128);
-       ctx->search_start_time = ioloop_timeval;
-
-       value = mail_user_plugin_getenv(box->storage->user, "fts_index_timeout");
-       if (value != NULL) {
-               if (settings_get_time(value, &ctx->timeout_secs, &error) < 0)
-                       i_error("Invalid fts_index_timeout setting: %s", error);
-       }
-
-
-       *ctx_r = ctx;
-       return 1;
-}
-
 int fts_indexer_deinit(struct fts_indexer_context **_ctx)
 {
        struct fts_indexer_context *ctx = *_ctx;
@@ -252,3 +201,53 @@ int fts_indexer_more(struct fts_indexer_context *ctx)
                fts_indexer_notify(ctx);
        return ret;
 }
+
+int fts_indexer_init(struct fts_backend *backend, struct mailbox *box,
+                    struct fts_indexer_context **ctx_r)
+{
+       struct fts_indexer_context *ctx;
+       struct mailbox_status status;
+       uint32_t last_uid, seq1, seq2;
+       const char *path, *cmd, *value, *error;
+       int fd;
+
+       if (fts_backend_get_last_uid(backend, box, &last_uid) < 0)
+               return -1;
+
+       mailbox_get_open_status(box, STATUS_UIDNEXT, &status);
+       if (status.uidnext == last_uid+1) {
+               /* everything is already indexed */
+               return 0;
+       }
+
+       mailbox_get_seq_range(box, last_uid+1, (uint32_t)-1, &seq1, &seq2);
+       if (seq1 == 0) {
+               /* no new messages (last messages in mailbox were expunged) */
+               return 0;
+       }
+
+       cmd = t_strdup_printf("PREPEND\t1\t%s\t%s\t0\t%s\n",
+                             str_tabescape(box->storage->user->username),
+                             str_tabescape(box->vname),
+                             str_tabescape(box->storage->user->session_id));
+       fd = fts_indexer_cmd(box->storage->user, cmd, &path);
+       if (fd == -1)
+               return -1;
+
+       /* connect to indexer and request immediate indexing of the mailbox */
+       ctx = i_new(struct fts_indexer_context, 1);
+       ctx->box = box;
+       ctx->conn.label = i_strdup(path);
+       ctx->conn.fd_in = fd;
+       ctx->conn.input = i_stream_create_fd(fd, 128);
+       ctx->search_start_time = ioloop_timeval;
+
+       value = mail_user_plugin_getenv(box->storage->user, "fts_index_timeout");
+       if (value != NULL) {
+               if (settings_get_time(value, &ctx->timeout_secs, &error) < 0)
+                       i_error("Invalid fts_index_timeout setting: %s", error);
+       }
+
+       *ctx_r = ctx;
+       return 1;
+}