diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f28cc61..8eafb109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to paopao-ce are documented in this file. 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_comment AS SELECT P.*,C.user_id comment_user_id FROM (SELECT post_id,user_id FROM p_comment WHERE is_del=0 UNION SELECT post_id,reply.user_id user_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/tweets.go b/internal/dao/jinzhu/tweets.go index ec0b3fff..d7bead87 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -438,7 +438,7 @@ 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) + db = db.Where("visibility IN ? AND is_del=0", visibilities) err = db.Count(&total).Error if err != nil { return @@ -451,12 +451,12 @@ func (s *tweetSrv) getUserTweets(db *gorm.DB, user *cs.VistUser, limit int, offs } func (s *tweetSrv) ListUserMediaTweets(user *cs.VistUser, limit int, offset int) ([]*ms.Post, int64, error) { - db := s.db.Table(_post_by_media_) + db := s.db.Table(_post_by_media_).Where("user_id=?", user.UserId) return s.getUserTweets(db, user, limit, offset) } func (s *tweetSrv) ListUserCommentTweets(user *cs.VistUser, limit int, offset int) ([]*ms.Post, int64, error) { - db := s.db.Table(_post_by_comment_) + db := s.db.Table(_post_by_comment_).Where("comment_user_id=?", user.UserId) return s.getUserTweets(db, user, limit, offset) } diff --git a/scripts/migration/mysql/0009_create_view_post_filter.up.sql b/scripts/migration/mysql/0009_create_view_post_filter.up.sql index af3e1c43..1ac93bf3 100644 --- a/scripts/migration/mysql/0009_create_view_post_filter.up.sql +++ b/scripts/migration/mysql/0009_create_view_post_filter.up.sql @@ -7,17 +7,19 @@ WHERE post.is_del = 0; CREATE VIEW p_post_by_comment AS -SELECT P.* +SELECT P.*, C.user_id comment_user_id FROM ( SELECT - post_id + post_id, + user_id FROM p_comment WHERE is_del = 0 UNION SELECT - post_id + post_id, + reply.user_id user_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID diff --git a/scripts/migration/postgres/0008_create_view_post_filter.up.sql b/scripts/migration/postgres/0008_create_view_post_filter.up.sql index af3e1c43..b0e62a31 100644 --- a/scripts/migration/postgres/0008_create_view_post_filter.up.sql +++ b/scripts/migration/postgres/0008_create_view_post_filter.up.sql @@ -7,17 +7,19 @@ WHERE post.is_del = 0; CREATE VIEW p_post_by_comment AS -SELECT P.* +SELECT P.*, C.user_id comment_user_id FROM ( SELECT - post_id + post_id, + user_id FROM p_comment WHERE is_del = 0 UNION SELECT - post_id + post_id, + reply.user_id user_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID @@ -27,4 +29,4 @@ FROM ) C JOIN p_post P ON C.post_id = P.ID WHERE - P.is_del = 0; + P.is_del = 0; \ No newline at end of file diff --git a/scripts/migration/sqlite3/0009_create_view_post_filter.up.sql b/scripts/migration/sqlite3/0009_create_view_post_filter.up.sql index af3e1c43..1ac93bf3 100644 --- a/scripts/migration/sqlite3/0009_create_view_post_filter.up.sql +++ b/scripts/migration/sqlite3/0009_create_view_post_filter.up.sql @@ -7,17 +7,19 @@ WHERE post.is_del = 0; CREATE VIEW p_post_by_comment AS -SELECT P.* +SELECT P.*, C.user_id comment_user_id FROM ( SELECT - post_id + post_id, + user_id FROM p_comment WHERE is_del = 0 UNION SELECT - post_id + post_id, + reply.user_id user_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID diff --git a/scripts/paopao-mysql.sql b/scripts/paopao-mysql.sql index 76cec80a..1e2401c7 100644 --- a/scripts/paopao-mysql.sql +++ b/scripts/paopao-mysql.sql @@ -406,17 +406,19 @@ WHERE DROP VIEW IF EXISTS p_post_by_comment; CREATE VIEW p_post_by_comment AS -SELECT P.* +SELECT P.*, C.user_id comment_user_id FROM ( SELECT - post_id + post_id, + user_id FROM p_comment WHERE is_del = 0 UNION SELECT - post_id + post_id, + reply.user_id user_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID diff --git a/scripts/paopao-postgres.sql b/scripts/paopao-postgres.sql index 4ea5b019..c21fc2ac 100644 --- a/scripts/paopao-postgres.sql +++ b/scripts/paopao-postgres.sql @@ -337,17 +337,19 @@ WHERE DROP VIEW IF EXISTS p_post_by_comment; CREATE VIEW p_post_by_comment AS -SELECT P.* +SELECT P.*, C.user_id comment_user_id FROM ( SELECT - post_id + post_id, + user_id FROM p_comment WHERE is_del = 0 UNION SELECT - post_id + post_id, + reply.user_id user_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID diff --git a/scripts/paopao-sqlite3.sql b/scripts/paopao-sqlite3.sql index 2d8a6e32..fc17748e 100644 --- a/scripts/paopao-sqlite3.sql +++ b/scripts/paopao-sqlite3.sql @@ -367,17 +367,19 @@ WHERE DROP VIEW IF EXISTS p_post_by_comment; CREATE VIEW p_post_by_comment AS -SELECT P.* +SELECT P.*, C.user_id comment_user_id FROM ( SELECT - post_id + post_id, + user_id FROM p_comment WHERE is_del = 0 UNION SELECT - post_id + post_id, + reply.user_id user_id FROM p_comment_reply reply JOIN p_comment COMMENT ON reply.comment_id = COMMENT.ID