This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/dev by this push:
new 57b153c9 feat(user): add FilterEmptyString function and apply to user
ID filtering
57b153c9 is described below
commit 57b153c9a9df0773f2a9b51f673f830aa3fd9b52
Author: LinkinStars <[email protected]>
AuthorDate: Wed Dec 25 16:00:08 2024 +0800
feat(user): add FilterEmptyString function and apply to user ID filtering
---
internal/service/user_common/user.go | 1 +
pkg/checker/zero_string.go | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/internal/service/user_common/user.go
b/internal/service/user_common/user.go
index be15bbe7..d05ffd4b 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -141,6 +141,7 @@ func (us *UserCommon) UpdateQuestionCount(ctx
context.Context, userID string, nu
}
func (us *UserCommon) BatchUserBasicInfoByID(ctx context.Context, userIDs
[]string) (map[string]*schema.UserBasicInfo, error) {
+ userIDs = checker.FilterEmptyString(userIDs)
userMap := make(map[string]*schema.UserBasicInfo)
if len(userIDs) == 0 {
return userMap, nil
diff --git a/pkg/checker/zero_string.go b/pkg/checker/zero_string.go
index 7b7e3111..7789cf63 100644
--- a/pkg/checker/zero_string.go
+++ b/pkg/checker/zero_string.go
@@ -23,3 +23,14 @@ package checker
func IsNotZeroString(s string) bool {
return len(s) > 0 && s != "0"
}
+
+// FilterEmptyString filter empty string from string slice
+func FilterEmptyString(strs []string) []string {
+ var result []string
+ for _, str := range strs {
+ if IsNotZeroString(str) {
+ result = append(result, str)
+ }
+ }
+ return result
+}