diff --git a/internal/core/topics.go b/internal/core/topics.go index cbcc046a..9484baeb 100644 --- a/internal/core/topics.go +++ b/internal/core/topics.go @@ -12,6 +12,6 @@ import ( type TopicService interface { UpsertTags(userId int64, tags []string) (cs.TagInfoList, error) DecrTagsById(ids []int64) error - ListTags(typ cs.TagType, offset int, limit int) (cs.TagList, error) + ListTags(typ cs.TagType, limit int, offset int) (cs.TagList, error) TagsByKeyword(keyword string) (cs.TagInfoList, error) } diff --git a/internal/dao/sakila/topics.go b/internal/dao/sakila/topics.go index 44bbebf0..a23ebf01 100644 --- a/internal/dao/sakila/topics.go +++ b/internal/dao/sakila/topics.go @@ -100,12 +100,12 @@ func (s *topicServant) DecrTagsById(ids []int64) error { }) } -func (s *topicServant) ListTags(typ cs.TagType, offset int, limit int) (res cs.TagList, err error) { +func (s *topicServant) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagList, err error) { switch typ { case cs.TagTypeHot: - err = s.stmtHotTags.Select(&res, offset, limit) + err = s.stmtHotTags.Select(&res, limit, offset) case cs.TagTypeNew: - err = s.stmtNewestTags.Select(&res, offset, limit) + err = s.stmtNewestTags.Select(&res, limit, offset) } return } @@ -123,10 +123,10 @@ func (s *topicServant) TagsByKeyword(keyword string) (res cs.TagInfoList, err er func newTopicService(db *sqlx.DB) core.TopicService { return &topicServant{ sqlxServant: newSqlxServant(db), - stmtNewestTags: c(`SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC OFFSET ? LIMIT ?`), - stmtHotTags: c(`SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC OFFSET ? LIMIT ?`), - stmtTagsByKeywordA: c(`SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC OFFSET 0 LIMIT 6`), - stmtTagsByKeywordB: c(`SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC OFFSET 0 LIMIT 6`), + stmtNewestTags: c(`SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?`), + stmtHotTags: c(`SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?`), + stmtTagsByKeywordA: c(`SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6`), + stmtTagsByKeywordB: c(`SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6`), stmtInsertTag: c(`INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)`), sqlTagsByIdA: r(`SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0`), sqlTagsByIdB: r(`SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)`), diff --git a/internal/servants/web/broker/post.go b/internal/servants/web/broker/post.go index 12ae46de..e177dd27 100644 --- a/internal/servants/web/broker/post.go +++ b/internal/servants/web/broker/post.go @@ -535,7 +535,7 @@ func GetPostTags(param *PostTagsReq) (cs.TagList, error) { if num > conf.AppSetting.MaxPageSize { num = conf.AppSetting.MaxPageSize } - tags, err := ds.ListTags(param.Type, 0, num) + tags, err := ds.ListTags(param.Type, num, 0) if err != nil { return nil, err } diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index 2b10ad4a..abe82ad9 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -75,7 +75,7 @@ func (s *pubSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error if num > conf.AppSetting.MaxPageSize { num = conf.AppSetting.MaxPageSize } - tags, err := s.Ds.ListTags(req.Type, 0, num) + tags, err := s.Ds.ListTags(req.Type, num, 0) if err != nil { return nil, _errGetPostTagsFailed }