From 640ae6e3b95650a852e131101baa233d37c92faf Mon Sep 17 00:00:00 2001 From: LinkinStar Date: Wed, 4 Jan 2023 10:09:37 +0800 Subject: [PATCH] fix(question): Incorrect empty query condition in postgres causes query problem bug. Fix #148 --- i18n/en_US.yaml | 22 ++++++++++---------- internal/service/question_common/question.go | 12 ++++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index f249dc08..d5ecb88e 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -135,21 +135,21 @@ backend: other: "Username is already in use." set_avatar: other: "Avatar set failed." - config: - read_config_failed: - other: "Read config failed" - database: - connection_failed: - other: "Database connection failed" - create_table_failed: - other: "Create table failed" - install: - create_config_failed: - other: "Can’t create the config.yaml file." cannot_update_your_role: other: "You cannot modify your role." not_allowed_registration: other: "Currently the site is not open for registration" + config: + read_config_failed: + other: "Read config failed" + database: + connection_failed: + other: "Database connection failed" + create_table_failed: + other: "Create table failed" + install: + create_config_failed: + other: "Can’t create the config.yaml file." report: spam: name: diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go index f9fb6b07..3a525b89 100644 --- a/internal/service/question_common/question.go +++ b/internal/service/question_common/question.go @@ -190,9 +190,15 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser showinfo.Tags = tagmap userIds := make([]string, 0) - userIds = append(userIds, dbinfo.UserID) - userIds = append(userIds, dbinfo.LastEditUserID) - userIds = append(userIds, showinfo.LastAnsweredUserID) + if checker.IsNotZeroString(dbinfo.UserID) { + userIds = append(userIds, dbinfo.UserID) + } + if checker.IsNotZeroString(dbinfo.LastEditUserID) { + userIds = append(userIds, dbinfo.LastEditUserID) + } + if checker.IsNotZeroString(showinfo.LastAnsweredUserID) { + userIds = append(userIds, showinfo.LastAnsweredUserID) + } userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds) if err != nil { return showinfo, err