优化代码
This commit is contained in:
parent
c759dfcdf6
commit
c70bcf5895
|
@ -62,9 +62,9 @@ func GetCommentByIds(ctx context.Context, ids []uint64) ([]models.WpComments, er
|
|||
func getCommentByIds(args ...any) (map[uint64]models.WpComments, error) {
|
||||
ids := args[0].([]uint64)
|
||||
m := make(map[uint64]models.WpComments)
|
||||
r, err := models.Find[models.WpComments](models.SqlBuilder{
|
||||
r, err := models.SimpleFind[models.WpComments](models.SqlBuilder{
|
||||
{"comment_ID", "in", ""}, {"comment_approved", "1"},
|
||||
}, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64]))
|
||||
}, "*", helper.SliceMap(ids, helper.ToAny[uint64]))
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ func searchPostIds(args ...any) (ids PostIds, err error) {
|
|||
}
|
||||
|
||||
func getMaxPostId(...any) ([]uint64, error) {
|
||||
r, err := models.Find[models.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID", "", nil, nil, nil, 0)
|
||||
r, err := models.SimpleFind[models.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID")
|
||||
var id uint64
|
||||
if len(r) > 0 {
|
||||
id = r[0].Id
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
func getUsers(...any) (m map[uint64]models.WpUsers, err error) {
|
||||
m = make(map[uint64]models.WpUsers)
|
||||
r, err := models.Find[models.WpUsers](nil, "*", "", nil, nil, nil, 0)
|
||||
r, err := models.SimpleFind[models.WpUsers](nil, "*")
|
||||
for _, user := range r {
|
||||
m[user.Id] = user
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ func InitOptions() error {
|
|||
}
|
||||
|
||||
func InitTerms() (err error) {
|
||||
terms, err := Find[WpTerms](nil, "*", "", nil, nil, nil, 0)
|
||||
terms, err := SimpleFind[WpTerms](nil, "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, wpTerms := range terms {
|
||||
Terms[wpTerms.TermId] = wpTerms
|
||||
}
|
||||
termTax, err := Find[WpTermTaxonomy](nil, "*", "", nil, nil, nil, 0)
|
||||
termTax, err := SimpleFind[WpTermTaxonomy](nil, "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -297,9 +297,14 @@ func LastOne[T Model](where ParseWhere, fields string, in ...[]any) (T, error) {
|
|||
func SimpleFind[T Model](where ParseWhere, fields string, in ...[]any) ([]T, error) {
|
||||
var r []T
|
||||
var rr T
|
||||
w, args, err := where.ParseWhere(&in)
|
||||
if err != nil {
|
||||
return r, err
|
||||
var err error
|
||||
args := make([]any, 0, 0)
|
||||
var w string
|
||||
if where != nil {
|
||||
w, args, err = where.ParseWhere(&in)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
}
|
||||
tp := "select %s from %s %s"
|
||||
sql := fmt.Sprintf(tp, fields, rr.Table(), w)
|
||||
|
|
Loading…
Reference in New Issue
Block a user