From d14e2dd3fd58e02c8adbe2f6715778077199e2a4 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 12 Mar 2024 23:18:51 +0900 Subject: [PATCH] Use simple query without JOIN in admin comment list, to improve query speed with millions of comments --- modules/comment/comment.model.php | 42 ++++++++++++++++++- .../getTotalCommentListWithoutJoin.xml | 30 +++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 modules/comment/queries/getTotalCommentListWithoutJoin.xml diff --git a/modules/comment/comment.model.php b/modules/comment/comment.model.php index c8c69352e..fa0d7a9e7 100644 --- a/modules/comment/comment.model.php +++ b/modules/comment/comment.model.php @@ -960,6 +960,15 @@ class CommentModel extends Comment return $output; } + // Use simple query without JOIN if there are no document-related conditions. + if ($query_id === 'comment.getTotalCommentList') + { + if (!$args->s_module_srl && !$args->exclude_module_srl && !$args->document_statusList) + { + $query_id = 'comment.getTotalCommentListWithoutJoin'; + } + } + // If an alternate output is set, use it instead of running the default queries if (isset($args->use_alternate_output) && $args->use_alternate_output instanceof BaseObject) { @@ -977,9 +986,40 @@ class CommentModel extends Comment return $output; } + // Fill in document-related fields if a simple query was used. + if ($query_id === 'comment.getTotalCommentListWithoutJoin') + { + $document_srl_list = []; + foreach ($output->data as $val) + { + $document_srl_list[$val->document_srl] = true; + } + if (count($document_srl_list)) + { + $document_list = DocumentModel::getDocuments(array_keys($document_srl_list), false, false, [ + 'document_srl', 'module_srl', 'member_srl', 'user_id', 'user_name', 'nick_name', 'title', + ]); + foreach ($document_list as $val) + { + $document_srl_list[$val->document_srl] = $val; + } + foreach ($output->data as $val) + { + if (isset($document_srl_list[$val->document_srl])) + { + $val->module_srl = $document_srl_list[$val->document_srl]->get('module_srl'); + $val->document_member_srl = $document_srl_list[$val->document_srl]->get('member_srl'); + $val->document_user_id = $document_srl_list[$val->document_srl]->get('user_id'); + $val->document_user_name = $document_srl_list[$val->document_srl]->get('user_name'); + $val->document_nick_name = $document_srl_list[$val->document_srl]->get('nick_name'); + $val->document_title = $document_srl_list[$val->document_srl]->get('title'); + } + } + } + } + foreach($output->data as $key => $val) { - unset($_oComment); $_oComment = new CommentItem(0); $_oComment->setAttribute($val); $output->data[$key] = $_oComment; diff --git a/modules/comment/queries/getTotalCommentListWithoutJoin.xml b/modules/comment/queries/getTotalCommentListWithoutJoin.xml new file mode 100644 index 000000000..4be8095ad --- /dev/null +++ b/modules/comment/queries/getTotalCommentListWithoutJoin.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +