diff --git a/CHANGELOG.md b/CHANGELOG.md index 65affa16..0f28cc61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,35 +9,8 @@ All notable changes to paopao-ce are documented in this file. - simple support for user posts filter by style(post/comment/media/star). [#345](https://github.com/rocboss/paopao-ce/pull/345) mirgration database first(sql ddl file in `scripts/migration/**/*_create_view_post_filter.up.sql`): ```sql - CREATE VIEW p_post_by_media AS - SELECT post.* - FROM - ( SELECT DISTINCT post_id FROM p_post_content WHERE ( TYPE = 3 OR TYPE = 4 OR TYPE = 7 OR TYPE = 8 ) AND is_del = 0 ) media - JOIN p_post post ON media.post_id = post.ID - WHERE - post.is_del = 0; - - CREATE VIEW p_post_by_comment AS - SELECT P.* - FROM - ( - SELECT - post_id - FROM - p_comment - WHERE - is_del = 0 UNION - SELECT - post_id - FROM - p_comment_reply reply - JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID - WHERE - reply.is_del = 0 AND COMMENT.is_del = 0 - ) - C JOIN p_post P ON C.post_id = P.ID - WHERE - P.is_del = 0; + CREATE VIEW p_post_by_media AS SELECT post.*FROM (SELECT DISTINCT post_id FROM p_post_content WHERE (TYPE=3 OR TYPE=4 OR TYPE=7 OR TYPE=8) AND is_del=0) media JOIN p_post post ON media.post_id=post.ID WHERE post.is_del=0; + CREATE VIEW p_post_by_comment AS SELECT P.*FROM (SELECT post_id FROM p_comment WHERE is_del=0 UNION SELECT post_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id=COMMENT.ID WHERE reply.is_del=0 AND COMMENT.is_del=0) C JOIN p_post P ON C.post_id=P.ID WHERE P.is_del=0; ``` - add user highlight tweet support include custom tweet set to highlight and list in user/profile page. diff --git a/internal/dao/jinzhu/topics.go b/internal/dao/jinzhu/topics.go index de317164..aedca3f3 100644 --- a/internal/dao/jinzhu/topics.go +++ b/internal/dao/jinzhu/topics.go @@ -143,7 +143,7 @@ func (s *topicSrv) GetFollowTags(userId int64, limit int, offset int) (cs.TagLis } // 置顶排序后处理 // TODO: 垃圾办法,最好是topic_user join tag 一次查询,但是gorm的join真他喵的别扭,F*K - res := make(cs.TagList, len(topicIds), len(topicIds)) + res := make(cs.TagList, len(topicIds)) for _, tag := range formtedTags { res[topicIdsMap[tag.ID]] = tag } @@ -217,10 +217,8 @@ func (s *topicSrv) tagsFormatA(userId int64, tags cs.TagList) (cs.TagList, error func (s *topicSrv) tagsFormatB(userTopicsMap map[int64]*topicInfo, tags cs.TagInfoList) (cs.TagList, error) { // 获取创建者User IDs userIds := []int64{} - tagIds := []int64{} for _, tag := range tags { userIds = append(userIds, tag.UserID) - tagIds = append(tagIds, tag.ID) } users, err := (&dbr.User{}).ListUserInfoById(s.db, userIds) if err != nil { diff --git a/internal/dao/jinzhu/tweets.go b/internal/dao/jinzhu/tweets.go index 29adb165..ec0b3fff 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -438,14 +438,15 @@ func (s *tweetSrv) getUserTweets(db *gorm.DB, user *cs.VistUser, limit int, offs default: // nothing } - db = db.Where("user_id=? AND visibility IN ? AND is_del=0", user.UserId, visibilities).Order("latest_replied_on DESC") + db = db.Where("user_id=? AND visibility IN ? AND is_del=0", user.UserId, visibilities) + err = db.Count(&total).Error + if err != nil { + return + } if offset >= 0 && limit > 0 { db = db.Offset(offset).Limit(limit) } - if err = db.Find(&res).Error; err != nil { - return - } - err = db.Count(&total).Error + err = db.Order("latest_replied_on DESC").Find(&res).Error return }