adapt for v0.5.0-beta.1

r/paopao-ce-plus
Michael Li 1 year ago
parent bb7884510a
commit 1a2863875e
No known key found for this signature in database

@ -8,5 +8,5 @@ type TrendsItem struct {
Username string `json:"username"` Username string `json:"username"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
IsFresh bool `json:"is_fresh" gorm:"-"` IsFresh bool `json:"is_fresh" gorm:"-" db:"-"`
} }

@ -26,23 +26,30 @@ const (
_Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0` _Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0`
_Comment_GetCommentThumbs = `SELECT user_id, tweet_id, comment_id, reply_id, comment_type, is_thumbs_up, is_thumbs_down FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?` _Comment_GetCommentThumbs = `SELECT user_id, tweet_id, comment_id, reply_id, comment_type, is_thumbs_up, is_thumbs_down FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?`
_Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC` _Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC`
_Comment_GetDefaultComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY id ASC LIMIT ? OFFSET ?` _Comment_GetDefaultComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY is_essence DESC, id ASC LIMIT ? OFFSET ?`
_Comment_GetHotsComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY thumbs_up_count DESC, id DESC LIMIT ? OFFSET ?` _Comment_GetHotsComments = `SELECT c.* FROM @comment c LEFT JOIN @comment_metric m ON c.id=m.comment_id WHERE c.post_id=? AND c.is_del=0 AND m.is_del=0 ORDER BY is_essence DESC, m.rank_score DESC, id DESC LIMIT ? OFFSET ?`
_Comment_GetNewestComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` _Comment_GetNewestComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY is_essence DESC, id DESC LIMIT ? OFFSET ?`
_Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?)` _Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?)`
_CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?)` _CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?)`
_CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?)` _CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?)`
_CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)` _CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)`
_CommentManage_CreateThumbsUpdownComment = `INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on)` _CommentManage_CreateThumbsUpdownComment = `INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on)`
_CommentManage_DecrCommentReplyCount = `UPDATE @comment SET reply_count=reply_count-1, modified_on=? WHERE id=? AND is_del=0`
_CommentManage_DeleteComment = `UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0` _CommentManage_DeleteComment = `UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0`
_CommentManage_DeleteCommentReply = `UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0` _CommentManage_DeleteCommentReply = `UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0`
_CommentManage_DeleteCommentThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0` _CommentManage_DeleteCommentThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0`
_CommentManage_DeleteReplyThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0` _CommentManage_DeleteReplyThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0`
_CommentManage_GetCommentReplyThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0` _CommentManage_GetCommentReplyThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0`
_CommentManage_GetTweetCommentThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0` _CommentManage_GetTweetCommentThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0`
_CommentManage_IncrCommentReplyCount = `UPDATE @comment SET reply_count=reply_count+1, modified_on=? WHERE id=? AND is_del=0`
_CommentManage_UpdateCommentThumbsCount = `UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0` _CommentManage_UpdateCommentThumbsCount = `UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0`
_CommentManage_UpdateReplyThumbsCount = `UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0` _CommentManage_UpdateReplyThumbsCount = `UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0`
_CommentManage_UpdateThumbsUpdownComment = `UPDATE @tweet_comment_thumbs SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on WHERE id=:id AND is_del=0` _CommentManage_UpdateThumbsUpdownComment = `UPDATE @tweet_comment_thumbs SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on WHERE id=:id AND is_del=0`
_CommentMetrics_AddCommentMetric = `INSERT INTO @comment_metric (comment_id, created_on) VALUES (?, ?)`
_CommentMetrics_DeleteCommentMetric = `UPDATE @comment_metric SET is_del=1, deleted_on=? WHERE comment_id=? AND is_del=0`
_CommentMetrics_GetMotivationFactor = `SELECT motivation_factor FROM @comment_metric WHERE comment_id=? AND is_del=0`
_CommentMetrics_UpdateRankScore = `UPDATE @comment_metric SET rank_score=?, modified_on=? WHERE comment_id=? AND is_del=0`
_CommentMetrics_UpsertCommentMetric = `INSERT INTO @comment_metric (comment_id, rank_score, created_on) VALUES (?, ?, ?)`
_ContactManager_AddFriendMsgsUpdate = `UPDATE @message SET reply_id=?, modified_on=? WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?` _ContactManager_AddFriendMsgsUpdate = `UPDATE @message SET reply_id=?, modified_on=? WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?`
_ContactManager_CreateContact = `INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?)` _ContactManager_CreateContact = `INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?)`
_ContactManager_CreateMessage = `INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on)` _ContactManager_CreateMessage = `INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on)`
@ -62,11 +69,19 @@ const (
_FollowingManager_ExistFollowing = `SELECT 1 FROM @following WHERE user_id=? AND follow_id=? AND is_del=0` _FollowingManager_ExistFollowing = `SELECT 1 FROM @following WHERE user_id=? AND follow_id=? AND is_del=0`
_FollowingManager_ListFollowings = `SELECT u.id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.created_on created_on FROM @following f JOIN @user u ON f.user_id=u.id WHERE f.follow_id=? AND f.is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?` _FollowingManager_ListFollowings = `SELECT u.id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.created_on created_on FROM @following f JOIN @user u ON f.user_id=u.id WHERE f.follow_id=? AND f.is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?`
_FollowingManager_ListFollows = `SELECT u.id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.created_on created_on FROM @following f JOIN @user u ON f.follow_id=u.id WHERE f.user_id=? AND f.is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?` _FollowingManager_ListFollows = `SELECT u.id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.created_on created_on FROM @following f JOIN @user u ON f.follow_id=u.id WHERE f.user_id=? AND f.is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?`
_Message_CountAllMessages = `SELECT count(*) FROM @message WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0`
_Message_CountRequestingMessages = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND type=5 AND is_del=0`
_Message_CountSystemMessages = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND type IN (1, 2, 3, 99) AND is_del=0`
_Message_CountUnreadMessages = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0`
_Message_CountWhisperMessages = `SELECT count(*) FROM @message WHERE ((receiver_user_id=? OR sender_user_id=?) AND type=4) AND is_del=0`
_Message_CreateMessage = `INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on)` _Message_CreateMessage = `INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on)`
_Message_GetAllMessages = `SELECT * FROM @message WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_GetMessageById = `SELECT * FROM @message WHERE id=? AND is_del=0` _Message_GetMessageById = `SELECT * FROM @message WHERE id=? AND is_del=0`
_Message_GetMessageCount = `SELECT count(*) FROM @message WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0` _Message_GetRequestingMessages = `SELECT * FROM @message WHERE receiver_user_id=? AND type=5 AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_GetMessages = `SELECT * FROM @message WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` _Message_GetSystemMessages = `SELECT * FROM @message WHERE receiver_user_id=? AND type IN (1, 2, 3, 99) AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0` _Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0`
_Message_GetUnreadMessages = `SELECT * FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_GetWhisperMessages = `SELECT * FROM @message WHERE ((receiver_user_id=? OR sender_user_id=?) AND type=4) AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?` _Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?`
_Security_CreatePhoneCaptcha = `INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on)` _Security_CreatePhoneCaptcha = `INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on)`
_Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=? AND is_del=0` _Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=? AND is_del=0`
@ -79,6 +94,8 @@ const (
_ShipIndex_IndexCountBySelf = `SELECT count(*) FROM @post WHERE is_del=0 AND (visibility=90 OR (visibility=0 AND user_id=?) OR (visibility=50 AND user_id IN (?)))` _ShipIndex_IndexCountBySelf = `SELECT count(*) FROM @post WHERE is_del=0 AND (visibility=90 OR (visibility=0 AND user_id=?) OR (visibility=50 AND user_id IN (?)))`
_SimpleIndex_Index = `SELECT * FROM @post WHERE visibility=90 ORDER BY is_top DESC, latest_replied_on DESC LIMIT ? OFFSET ?` _SimpleIndex_Index = `SELECT * FROM @post WHERE visibility=90 ORDER BY is_top DESC, latest_replied_on DESC LIMIT ? OFFSET ?`
_SimpleIndex_IndexCount = `SELECT count(*) FROM @post WHERE visibility=90` _SimpleIndex_IndexCount = `SELECT count(*) FROM @post WHERE visibility=90`
_TrendsManager_CountIndexTrends = `SELECT count(*) FROM @contact c JOIN @user u ON c.friend_id=u.id JOIN @user_metric m ON c.friend_id=m.user_id WHERE c.user_id=? AND c.is_del=0 AND u.is_del=0 AND m.is_del=0 AND m.tweets_count>0`
_TrendsManager_GetIndexTrends = `SELECT u.username username, u.nickname nickname, u.avatar avatar FROM @contact c JOIN @user u ON c.friend_id=u.id JOIN @user_metric m ON c.friend_id=m.user_id WHERE c.user_id=? AND c.is_del=0 AND u.is_del=0 AND m.is_del=0 AND m.tweets_count>0 LIMIT ? OFFSET ?`
_Tweet_CountFollowingTweets = `SELECT count(*) FROM @post WHERE user_id=? AND is_del=0` _Tweet_CountFollowingTweets = `SELECT count(*) FROM @post WHERE user_id=? AND is_del=0`
_Tweet_CountFollowingTweetsFollow = `SELECT count(*) FROM @post WHERE (user_id=? OR (visibility>=60 AND user_id IN(?))) AND is_del=0` _Tweet_CountFollowingTweetsFollow = `SELECT count(*) FROM @post WHERE (user_id=? OR (visibility>=60 AND user_id IN(?))) AND is_del=0`
_Tweet_CountFollowingTweetsFriend = `SELECT count(*) FROM @post WHERE (user_id=? OR (visibility>=50 AND user_id IN(?))) AND is_del=0` _Tweet_CountFollowingTweetsFriend = `SELECT count(*) FROM @post WHERE (user_id=? OR (visibility>=50 AND user_id IN(?))) AND is_del=0`
@ -137,6 +154,7 @@ const (
_TweetMetrics_DeleteTweetMetric = `UPDATE @post_metric SET is_del=1, deleted_on=? WHERE post_id=? AND is_del=0` _TweetMetrics_DeleteTweetMetric = `UPDATE @post_metric SET is_del=1, deleted_on=? WHERE post_id=? AND is_del=0`
_TweetMetrics_GetMotivationFactor = `SELECT motivation_factor FROM @post_metric WHERE post_id=? AND is_del=0` _TweetMetrics_GetMotivationFactor = `SELECT motivation_factor FROM @post_metric WHERE post_id=? AND is_del=0`
_TweetMetrics_UpdateRankScore = `UPDATE @post_metric SET rank_score=?, modified_on=? WHERE post_id=? AND is_del=0` _TweetMetrics_UpdateRankScore = `UPDATE @post_metric SET rank_score=?, modified_on=? WHERE post_id=? AND is_del=0`
_TweetMetrics_UpsertTweetMetric = `INSERT INTO @post_metric (post_id, rank_score, created_on) VALUES (?, ?, ?)`
_Tweet_UserCommentTweetsByFriend = `SELECT id, user_id, comment_count, collection_count, upvote_count, share_count, visibility, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del FROM @post_by_comment WHERE is_del=0 AND comment_user_id=? AND visibility>=50 ORDER BY latest_replied_on DESC LIMIT ? OFFSET ?` _Tweet_UserCommentTweetsByFriend = `SELECT id, user_id, comment_count, collection_count, upvote_count, share_count, visibility, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del FROM @post_by_comment WHERE is_del=0 AND comment_user_id=? AND visibility>=50 ORDER BY latest_replied_on DESC LIMIT ? OFFSET ?`
_Tweet_UserCommentTweetsByGuest = `SELECT id, user_id, comment_count, collection_count, upvote_count, share_count, visibility, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del FROM @post_by_comment WHERE is_del=0 AND comment_user_id=? AND visibility>=90 ORDER BY latest_replied_on DESC LIMIT ? OFFSET ?` _Tweet_UserCommentTweetsByGuest = `SELECT id, user_id, comment_count, collection_count, upvote_count, share_count, visibility, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del FROM @post_by_comment WHERE is_del=0 AND comment_user_id=? AND visibility>=90 ORDER BY latest_replied_on DESC LIMIT ? OFFSET ?`
_Tweet_UserCommentTweetsBySelf = `SELECT id, user_id, comment_count, collection_count, upvote_count, share_count, visibility, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del FROM @post_by_comment WHERE is_del=0 AND comment_user_id=? ORDER BY latest_replied_on DESC LIMIT ? OFFSET ?` _Tweet_UserCommentTweetsBySelf = `SELECT id, user_id, comment_count, collection_count, upvote_count, share_count, visibility, is_top, is_essence, is_lock, latest_replied_on, tags, attachment_price, ip, ip_loc, created_on, modified_on, deleted_on, is_del FROM @post_by_comment WHERE is_del=0 AND comment_user_id=? ORDER BY latest_replied_on DESC LIMIT ? OFFSET ?`
@ -166,6 +184,12 @@ const (
_UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN (?) AND is_del=0` _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN (?) AND is_del=0`
_UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6` _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6`
_UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0` _UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0`
_UserMetrics_AddUserMetric = `INSERT INTO @user_metric (user_id, created_on) VALUES (?, ?)`
_UserMetrics_DeleteUserMetric = `UPDATE @user_metric SET is_del=1, deleted_on=? WHERE user_id=? AND is_del=0`
_UserMetrics_GetTweetsCount = `SELECT tweets_count FROM @user_metric WHERE user_id=? AND is_del=0`
_UserMetrics_UpdateUserMetric = `UPDATE @user_metric SET tweets_count=?, modified_on=? WHERE user_id=? AND is_del=0`
_UserRelation_MyFollowIds = `SELECT follow_id FROM @following WHERE user_id=? AND is_del=0`
_UserRelation_MyFriendIds = `SELECT friend_id FROM @contact WHERE user_id=? AND is_del=0`
_Wallet_AddUserBalance = `UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0` _Wallet_AddUserBalance = `UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0`
_Wallet_CreateRecharge = `INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?)` _Wallet_CreateRecharge = `INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?)`
_Wallet_CreateWalletStatement = `INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?)` _Wallet_CreateWalletStatement = `INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?)`
@ -226,18 +250,29 @@ type CommentManage struct {
CreateComment *sqlx.Stmt `yesql:"create_comment"` CreateComment *sqlx.Stmt `yesql:"create_comment"`
CreateCommentContent *sqlx.Stmt `yesql:"create_comment_content"` CreateCommentContent *sqlx.Stmt `yesql:"create_comment_content"`
CreateCommentReply *sqlx.Stmt `yesql:"create_comment_reply"` CreateCommentReply *sqlx.Stmt `yesql:"create_comment_reply"`
DecrCommentReplyCount *sqlx.Stmt `yesql:"decr_comment_reply_count"`
DeleteComment *sqlx.Stmt `yesql:"delete_comment"` DeleteComment *sqlx.Stmt `yesql:"delete_comment"`
DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"` DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"`
DeleteCommentThumbs *sqlx.Stmt `yesql:"delete_comment_thumbs"` DeleteCommentThumbs *sqlx.Stmt `yesql:"delete_comment_thumbs"`
DeleteReplyThumbs *sqlx.Stmt `yesql:"delete_reply_thumbs"` DeleteReplyThumbs *sqlx.Stmt `yesql:"delete_reply_thumbs"`
GetCommentReplyThumb *sqlx.Stmt `yesql:"get_comment_reply_thumb"` GetCommentReplyThumb *sqlx.Stmt `yesql:"get_comment_reply_thumb"`
GetTweetCommentThumb *sqlx.Stmt `yesql:"get_tweet_comment_thumb"` GetTweetCommentThumb *sqlx.Stmt `yesql:"get_tweet_comment_thumb"`
IncrCommentReplyCount *sqlx.Stmt `yesql:"incr_comment_reply_count"`
UpdateCommentThumbsCount *sqlx.Stmt `yesql:"update_comment_thumbs_count"` UpdateCommentThumbsCount *sqlx.Stmt `yesql:"update_comment_thumbs_count"`
UpdateReplyThumbsCount *sqlx.Stmt `yesql:"update_reply_thumbs_count"` UpdateReplyThumbsCount *sqlx.Stmt `yesql:"update_reply_thumbs_count"`
CreateThumbsUpdownComment *sqlx.NamedStmt `yesql:"create_thumbs_updown_comment"` CreateThumbsUpdownComment *sqlx.NamedStmt `yesql:"create_thumbs_updown_comment"`
UpdateThumbsUpdownComment *sqlx.NamedStmt `yesql:"update_thumbs_updown_comment"` UpdateThumbsUpdownComment *sqlx.NamedStmt `yesql:"update_thumbs_updown_comment"`
} }
type CommentMetrics struct {
yesql.Namespace `yesql:"comment_metrics"`
AddCommentMetric *sqlx.Stmt `yesql:"add_comment_metric"`
DeleteCommentMetric *sqlx.Stmt `yesql:"delete_comment_metric"`
GetMotivationFactor *sqlx.Stmt `yesql:"get_motivation_factor"`
UpdateRankScore *sqlx.Stmt `yesql:"update_rank_score"`
UpsertCommentMetric *sqlx.Stmt `yesql:"upsert_comment_metric"`
}
type ContactManager struct { type ContactManager struct {
yesql.Namespace `yesql:"contact_manager"` yesql.Namespace `yesql:"contact_manager"`
AddFriendMsgsUpdate *sqlx.Stmt `yesql:"add_friend_msgs_update"` AddFriendMsgsUpdate *sqlx.Stmt `yesql:"add_friend_msgs_update"`
@ -266,13 +301,21 @@ type FollowingManager struct {
} }
type Message struct { type Message struct {
yesql.Namespace `yesql:"message"` yesql.Namespace `yesql:"message"`
GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"` CountAllMessages *sqlx.Stmt `yesql:"count_all_messages"`
GetMessageCount *sqlx.Stmt `yesql:"get_message_count"` CountRequestingMessages *sqlx.Stmt `yesql:"count_requesting_messages"`
GetMessages *sqlx.Stmt `yesql:"get_messages"` CountSystemMessages *sqlx.Stmt `yesql:"count_system_messages"`
GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` CountUnreadMessages *sqlx.Stmt `yesql:"count_unread_messages"`
ReadMessage *sqlx.Stmt `yesql:"read_message"` CountWhisperMessages *sqlx.Stmt `yesql:"count_whisper_messages"`
CreateMessage *sqlx.NamedStmt `yesql:"create_message"` GetAllMessages *sqlx.Stmt `yesql:"get_all_messages"`
GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"`
GetRequestingMessages *sqlx.Stmt `yesql:"get_requesting_messages"`
GetSystemMessages *sqlx.Stmt `yesql:"get_system_messages"`
GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"`
GetUnreadMessages *sqlx.Stmt `yesql:"get_unread_messages"`
GetWhisperMessages *sqlx.Stmt `yesql:"get_whisper_messages"`
ReadMessage *sqlx.Stmt `yesql:"read_message"`
CreateMessage *sqlx.NamedStmt `yesql:"create_message"`
} }
type Security struct { type Security struct {
@ -298,6 +341,12 @@ type SimpleIndex struct {
IndexCount *sqlx.Stmt `yesql:"index_count"` IndexCount *sqlx.Stmt `yesql:"index_count"`
} }
type TrendsManager struct {
yesql.Namespace `yesql:"trends_manager"`
CountIndexTrends *sqlx.Stmt `yesql:"count_index_trends"`
GetIndexTrends *sqlx.Stmt `yesql:"get_index_trends"`
}
type Tweet struct { type Tweet struct {
yesql.Namespace `yesql:"tweet"` yesql.Namespace `yesql:"tweet"`
CountFollowingTweetsFollow string `yesql:"count_following_tweets_follow"` CountFollowingTweetsFollow string `yesql:"count_following_tweets_follow"`
@ -390,6 +439,7 @@ type TweetMetrics struct {
DeleteTweetMetric *sqlx.Stmt `yesql:"delete_tweet_metric"` DeleteTweetMetric *sqlx.Stmt `yesql:"delete_tweet_metric"`
GetMotivationFactor *sqlx.Stmt `yesql:"get_motivation_factor"` GetMotivationFactor *sqlx.Stmt `yesql:"get_motivation_factor"`
UpdateRankScore *sqlx.Stmt `yesql:"update_rank_score"` UpdateRankScore *sqlx.Stmt `yesql:"update_rank_score"`
UpsertTweetMetric *sqlx.Stmt `yesql:"upsert_tweet_metric"`
} }
type UserManage struct { type UserManage struct {
@ -405,6 +455,20 @@ type UserManage struct {
UpdateUser *sqlx.NamedStmt `yesql:"update_user"` UpdateUser *sqlx.NamedStmt `yesql:"update_user"`
} }
type UserMetrics struct {
yesql.Namespace `yesql:"user_metrics"`
AddUserMetric *sqlx.Stmt `yesql:"add_user_metric"`
DeleteUserMetric *sqlx.Stmt `yesql:"delete_user_metric"`
GetTweetsCount *sqlx.Stmt `yesql:"get_tweets_count"`
UpdateUserMetric *sqlx.Stmt `yesql:"update_user_metric"`
}
type UserRelation struct {
yesql.Namespace `yesql:"user_relation"`
MyFollowIds *sqlx.Stmt `yesql:"my_follow_ids"`
MyFriendIds *sqlx.Stmt `yesql:"my_friend_ids"`
}
type Wallet struct { type Wallet struct {
yesql.Namespace `yesql:"wallet"` yesql.Namespace `yesql:"wallet"`
AddUserBalance *sqlx.Stmt `yesql:"add_user_balance"` AddUserBalance *sqlx.Stmt `yesql:"add_user_balance"`
@ -494,6 +558,9 @@ func BuildCommentManage(p PreparexBuilder, ctx ...context.Context) (obj *Comment
if obj.CreateCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentReply))); err != nil { if obj.CreateCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentReply))); err != nil {
return nil, fmt.Errorf("prepare _CommentManage_CreateCommentReply error: %w", err) return nil, fmt.Errorf("prepare _CommentManage_CreateCommentReply error: %w", err)
} }
if obj.DecrCommentReplyCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DecrCommentReplyCount))); err != nil {
return nil, fmt.Errorf("prepare _CommentManage_DecrCommentReplyCount error: %w", err)
}
if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteComment))); err != nil { if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteComment))); err != nil {
return nil, fmt.Errorf("prepare _CommentManage_DeleteComment error: %w", err) return nil, fmt.Errorf("prepare _CommentManage_DeleteComment error: %w", err)
} }
@ -512,6 +579,9 @@ func BuildCommentManage(p PreparexBuilder, ctx ...context.Context) (obj *Comment
if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetTweetCommentThumb))); err != nil { if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetTweetCommentThumb))); err != nil {
return nil, fmt.Errorf("prepare _CommentManage_GetTweetCommentThumb error: %w", err) return nil, fmt.Errorf("prepare _CommentManage_GetTweetCommentThumb error: %w", err)
} }
if obj.IncrCommentReplyCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_IncrCommentReplyCount))); err != nil {
return nil, fmt.Errorf("prepare _CommentManage_IncrCommentReplyCount error: %w", err)
}
if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateCommentThumbsCount))); err != nil { if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateCommentThumbsCount))); err != nil {
return nil, fmt.Errorf("prepare _CommentManage_UpdateCommentThumbsCount error: %w", err) return nil, fmt.Errorf("prepare _CommentManage_UpdateCommentThumbsCount error: %w", err)
} }
@ -527,6 +597,32 @@ func BuildCommentManage(p PreparexBuilder, ctx ...context.Context) (obj *Comment
return return
} }
func BuildCommentMetrics(p PreparexBuilder, ctx ...context.Context) (obj *CommentMetrics, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &CommentMetrics{}
if obj.AddCommentMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentMetrics_AddCommentMetric))); err != nil {
return nil, fmt.Errorf("prepare _CommentMetrics_AddCommentMetric error: %w", err)
}
if obj.DeleteCommentMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentMetrics_DeleteCommentMetric))); err != nil {
return nil, fmt.Errorf("prepare _CommentMetrics_DeleteCommentMetric error: %w", err)
}
if obj.GetMotivationFactor, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentMetrics_GetMotivationFactor))); err != nil {
return nil, fmt.Errorf("prepare _CommentMetrics_GetMotivationFactor error: %w", err)
}
if obj.UpdateRankScore, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentMetrics_UpdateRankScore))); err != nil {
return nil, fmt.Errorf("prepare _CommentMetrics_UpdateRankScore error: %w", err)
}
if obj.UpsertCommentMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentMetrics_UpsertCommentMetric))); err != nil {
return nil, fmt.Errorf("prepare _CommentMetrics_UpsertCommentMetric error: %w", err)
}
return
}
func BuildContactManager(p PreparexBuilder, ctx ...context.Context) (obj *ContactManager, err error) { func BuildContactManager(p PreparexBuilder, ctx ...context.Context) (obj *ContactManager, err error) {
var c context.Context var c context.Context
if len(ctx) > 0 && ctx[0] != nil { if len(ctx) > 0 && ctx[0] != nil {
@ -614,18 +710,42 @@ func BuildMessage(p PreparexBuilder, ctx ...context.Context) (obj *Message, err
c = context.Background() c = context.Background()
} }
obj = &Message{} obj = &Message{}
if obj.CountAllMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_CountAllMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_CountAllMessages error: %w", err)
}
if obj.CountRequestingMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_CountRequestingMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_CountRequestingMessages error: %w", err)
}
if obj.CountSystemMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_CountSystemMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_CountSystemMessages error: %w", err)
}
if obj.CountUnreadMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_CountUnreadMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_CountUnreadMessages error: %w", err)
}
if obj.CountWhisperMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_CountWhisperMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_CountWhisperMessages error: %w", err)
}
if obj.GetAllMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetAllMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetAllMessages error: %w", err)
}
if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetMessageById))); err != nil { if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetMessageById))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetMessageById error: %w", err) return nil, fmt.Errorf("prepare _Message_GetMessageById error: %w", err)
} }
if obj.GetMessageCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetMessageCount))); err != nil { if obj.GetRequestingMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetRequestingMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetMessageCount error: %w", err) return nil, fmt.Errorf("prepare _Message_GetRequestingMessages error: %w", err)
} }
if obj.GetMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetMessages))); err != nil { if obj.GetSystemMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetSystemMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetMessages error: %w", err) return nil, fmt.Errorf("prepare _Message_GetSystemMessages error: %w", err)
} }
if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetUnreadCount))); err != nil { if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetUnreadCount))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetUnreadCount error: %w", err) return nil, fmt.Errorf("prepare _Message_GetUnreadCount error: %w", err)
} }
if obj.GetUnreadMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetUnreadMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetUnreadMessages error: %w", err)
}
if obj.GetWhisperMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetWhisperMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetWhisperMessages error: %w", err)
}
if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil { if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil {
return nil, fmt.Errorf("prepare _Message_ReadMessage error: %w", err) return nil, fmt.Errorf("prepare _Message_ReadMessage error: %w", err)
} }
@ -698,6 +818,23 @@ func BuildSimpleIndex(p PreparexBuilder, ctx ...context.Context) (obj *SimpleInd
return return
} }
func BuildTrendsManager(p PreparexBuilder, ctx ...context.Context) (obj *TrendsManager, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &TrendsManager{}
if obj.CountIndexTrends, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TrendsManager_CountIndexTrends))); err != nil {
return nil, fmt.Errorf("prepare _TrendsManager_CountIndexTrends error: %w", err)
}
if obj.GetIndexTrends, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TrendsManager_GetIndexTrends))); err != nil {
return nil, fmt.Errorf("prepare _TrendsManager_GetIndexTrends error: %w", err)
}
return
}
func BuildTweet(p PreparexBuilder, ctx ...context.Context) (obj *Tweet, err error) { func BuildTweet(p PreparexBuilder, ctx ...context.Context) (obj *Tweet, err error) {
var c context.Context var c context.Context
if len(ctx) > 0 && ctx[0] != nil { if len(ctx) > 0 && ctx[0] != nil {
@ -938,6 +1075,9 @@ func BuildTweetMetrics(p PreparexBuilder, ctx ...context.Context) (obj *TweetMet
if obj.UpdateRankScore, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetMetrics_UpdateRankScore))); err != nil { if obj.UpdateRankScore, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetMetrics_UpdateRankScore))); err != nil {
return nil, fmt.Errorf("prepare _TweetMetrics_UpdateRankScore error: %w", err) return nil, fmt.Errorf("prepare _TweetMetrics_UpdateRankScore error: %w", err)
} }
if obj.UpsertTweetMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetMetrics_UpsertTweetMetric))); err != nil {
return nil, fmt.Errorf("prepare _TweetMetrics_UpsertTweetMetric error: %w", err)
}
return return
} }
@ -978,6 +1118,46 @@ func BuildUserManage(p PreparexBuilder, ctx ...context.Context) (obj *UserManage
return return
} }
func BuildUserMetrics(p PreparexBuilder, ctx ...context.Context) (obj *UserMetrics, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &UserMetrics{}
if obj.AddUserMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserMetrics_AddUserMetric))); err != nil {
return nil, fmt.Errorf("prepare _UserMetrics_AddUserMetric error: %w", err)
}
if obj.DeleteUserMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserMetrics_DeleteUserMetric))); err != nil {
return nil, fmt.Errorf("prepare _UserMetrics_DeleteUserMetric error: %w", err)
}
if obj.GetTweetsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserMetrics_GetTweetsCount))); err != nil {
return nil, fmt.Errorf("prepare _UserMetrics_GetTweetsCount error: %w", err)
}
if obj.UpdateUserMetric, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserMetrics_UpdateUserMetric))); err != nil {
return nil, fmt.Errorf("prepare _UserMetrics_UpdateUserMetric error: %w", err)
}
return
}
func BuildUserRelation(p PreparexBuilder, ctx ...context.Context) (obj *UserRelation, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &UserRelation{}
if obj.MyFollowIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserRelation_MyFollowIds))); err != nil {
return nil, fmt.Errorf("prepare _UserRelation_MyFollowIds error: %w", err)
}
if obj.MyFriendIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserRelation_MyFriendIds))); err != nil {
return nil, fmt.Errorf("prepare _UserRelation_MyFriendIds error: %w", err)
}
return
}
func BuildWallet(p PreparexBuilder, ctx ...context.Context) (obj *Wallet, err error) { func BuildWallet(p PreparexBuilder, ctx ...context.Context) (obj *Wallet, err error) {
var c context.Context var c context.Context
if len(ctx) > 0 && ctx[0] != nil { if len(ctx) > 0 && ctx[0] != nil {

@ -17,6 +17,7 @@ var (
) )
const ( const (
_Comment_GetHotsComments = `SELECT c.* FROM @comment c LEFT JOIN @comment_metric m ON c.id=m.comment_id WHERE c.post_id=? AND c.is_del=0 AND m.is_del=0 ORDER BY is_essence DESC, m.rank_score DESC NULLS LAST, id DESC LIMIT ? OFFSET ?`
_CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?) RETURNING *` _CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?) RETURNING *`
_CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?) RETURNING *` _CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?) RETURNING *`
_CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *` _CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *`
@ -52,6 +53,11 @@ type PreparexBuilder interface {
QueryHook(query string) string QueryHook(query string) string
} }
type Comment struct {
yesql.Namespace `yesql:"comment"`
GetHotsComments *sqlx.Stmt `yesql:"get_hots_comments"`
}
type CommentManage struct { type CommentManage struct {
yesql.Namespace `yesql:"comment_manage"` yesql.Namespace `yesql:"comment_manage"`
CreateComment *sqlx.Stmt `yesql:"create_comment"` CreateComment *sqlx.Stmt `yesql:"create_comment"`
@ -93,6 +99,20 @@ type Wallet struct {
CreateRecharge *sqlx.Stmt `yesql:"create_recharge"` CreateRecharge *sqlx.Stmt `yesql:"create_recharge"`
} }
func BuildComment(p PreparexBuilder, ctx ...context.Context) (obj *Comment, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &Comment{}
if obj.GetHotsComments, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetHotsComments))); err != nil {
return nil, fmt.Errorf("prepare _Comment_GetHotsComments error: %w", err)
}
return
}
func BuildCommentManage(p PreparexBuilder, ctx ...context.Context) (obj *CommentManage, err error) { func BuildCommentManage(p PreparexBuilder, ctx ...context.Context) (obj *CommentManage, err error) {
var c context.Context var c context.Context
if len(ctx) > 0 && ctx[0] != nil { if len(ctx) > 0 && ctx[0] != nil {

@ -156,8 +156,9 @@ func (s *commentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) {
} }
func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) { func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) {
now := time.Now().Unix()
res, err := s.q.CreateCommentReply.Exec(r.CommentID, r.UserID, r.Content, res, err := s.q.CreateCommentReply.Exec(r.CommentID, r.UserID, r.Content,
r.AtUserID, r.IP, r.IPLoc, time.Now().Unix()) r.AtUserID, r.IP, r.IPLoc, now)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -166,17 +167,22 @@ func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentRe
return nil, err return nil, err
} }
r.Model = &ms.Model{ID: id} r.Model = &ms.Model{ID: id}
// 宽松处理错误
s.q.IncrCommentReplyCount.Exec(now, r.CommentID)
return r, nil return r, nil
} }
func (s *commentManageSrv) DeleteCommentReply(r *ms.CommentReply) error { func (s *commentManageSrv) DeleteCommentReply(r *ms.CommentReply) error {
return s.db.Withx(func(tx *sqlx.Tx) error { return s.db.Withx(func(tx *sqlx.Tx) (err error) {
now := time.Now().Unix() now := time.Now().Unix()
if _, err := tx.Stmtx(s.q.DeleteCommentReply).Exec(now, r.ID); err != nil { if _, err = tx.Stmtx(s.q.DeleteCommentReply).Exec(now, r.ID); err != nil {
return err return
} }
_, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(now, r.UserID, r.CommentID, r.ID) if _, err = tx.Stmtx(s.q.DeleteCommentThumbs).Exec(now, r.UserID, r.CommentID, r.ID); err == nil {
return err // 宽松处理错误
tx.Stmtx(s.q.DecrCommentReplyCount).Exec(now, r.CommentID)
}
return
}) })
} }
@ -393,11 +399,20 @@ func (s *commentManageSrv) HighlightComment(userId, commentId int64) (int8, erro
return 0, cs.ErrNotImplemented return 0, cs.ErrNotImplemented
} }
func newCommentService(db *sqlx.DB) core.CommentService { func newCommentService(db *sqlx.DB) (s core.CommentService) {
return &commentSrv{ cs := &commentSrv{
sqlxSrv: newSqlxSrv(db), sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildComment), q: ccBuild(db, cc.BuildComment),
} }
s = cs
if cfg.Any("PostgreSQL", "PgSQL", "Postgres") {
s = &pgcCommentSrv{
commentSrv: cs,
p: pgcBuild(db, pgc.BuildComment),
}
}
return
} }
func newCommentManageService(db *sqlx.DB) (s core.CommentManageService) { func newCommentManageService(db *sqlx.DB) (s core.CommentManageService) {

@ -9,6 +9,7 @@ import (
"github.com/bitbus/sqlx/db" "github.com/bitbus/sqlx/db"
"github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc"
) )
@ -22,19 +23,48 @@ type pgcCommentManageSrv struct {
p *pgc.CommentManage p *pgc.CommentManage
} }
type pgcCommentSrv struct {
*commentSrv
p *pgc.Comment
}
func (s *pgcCommentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) { func (s *pgcCommentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) {
return db.Get[ms.Comment](s.p.CreateComment, r.PostID, r.UserID, r.IP, r.IPLoc, time.Now().Unix()) return db.Get[ms.Comment](s.p.CreateComment, r.PostID, r.UserID, r.IP, r.IPLoc, time.Now().Unix())
} }
func (s *pgcCommentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) { func (s *pgcCommentManageSrv) CreateCommentReply(r *ms.CommentReply) (res *ms.CommentReply, err error) {
return db.Get[ms.CommentReply](s.p.CreateCommentReply, r.CommentID, now := time.Now().Unix()
if res, err = db.Get[ms.CommentReply](s.p.CreateCommentReply, r.CommentID,
r.UserID, r.Content, r.AtUserID, r.UserID, r.Content, r.AtUserID,
r.IP, r.IPLoc, time.Now().Unix()) r.IP, r.IPLoc, now); err == nil {
// 宽松处理错误
s.q.IncrCommentReplyCount.Exec(now, r.CommentID)
}
return
} }
func (s *pgcCommentManageSrv) CreateCommentContent(r *ms.CommentContent) (*ms.CommentContent, error) { func (s *pgcCommentManageSrv) CreateCommentContent(r *ms.CommentContent) (*ms.CommentContent, error) {
return db.Get[ms.CommentContent](s.p.CreateCommentContent, return db.Get[ms.CommentContent](s.p.CreateCommentContent,
r.CommentID, r.UserID, r.Content, r.CommentID, r.UserID, r.Content,
r.Type, r.Sort, time.Now().Unix()) r.Type, r.Sort, time.Now().Unix())
}
func (s *pgcCommentSrv) GetComments(tweetId int64, style cs.StyleCommentType, limit int, offset int) (res []*ms.Comment, total int64, err error) {
switch style {
case cs.StyleCommentHots:
if err = s.p.GetHotsComments.Select(&res, tweetId, limit, offset); err == nil {
err = s.q.GetCommentCount.Get(&total, tweetId)
}
case cs.StyleCommentNewest:
if err = s.q.GetNewestComments.Select(&res, tweetId, limit, offset); err == nil {
err = s.q.GetCommentCount.Get(&total, tweetId)
}
case cs.StyleCommentDefault:
fallthrough
default:
if err = s.q.GetDefaultComments.Select(&res, tweetId, limit, offset); err == nil {
err = s.q.GetCommentCount.Get(&total, tweetId)
}
}
return
} }

@ -11,10 +11,10 @@ import (
"github.com/bitbus/sqlx" "github.com/bitbus/sqlx"
"github.com/bitbus/sqlx/db" "github.com/bitbus/sqlx/db"
"github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc"
"github.com/sirupsen/logrus"
) )
var ( var (
@ -55,24 +55,40 @@ func (s *messageSrv) ReadMessage(r *ms.Message) (err error) {
return return
} }
func (s *messageSrv) GetMessages(userId int64, offset, limit int) ([]*ms.MessageFormated, error) { func (s *messageSrv) GetMessages(userId int64, style cs.MessageStyle, limit, offset int) (res []*ms.MessageFormated, total int64, err error) {
var messages []*ms.Message var messages []*ms.Message
if err := s.q.GetMessages.Select(&messages, userId, userId, limit, offset); err != nil { // 1动态2评论3回复4私信5好友申请99系统通知
return nil, err switch style {
} case cs.StyleMsgSystem:
mfs := make([]*ms.MessageFormated, 0, len(messages)) if err = s.q.CountSystemMessages.Get(&total, userId); err == nil && total > 0 {
for _, message := range messages { err = s.q.GetSystemMessages.Select(&messages, userId, limit, offset)
mf := message.Format() }
mfs = append(mfs, mf) case cs.StyleMsgWhisper:
if err = s.q.CountWhisperMessages.Get(&total, userId, userId); err == nil && total > 0 {
err = s.q.GetWhisperMessages.Select(&messages, userId, userId, limit, offset)
}
case cs.StyleMsgRequesting:
if err = s.q.CountRequestingMessages.Get(&total, userId); err == nil && total > 0 {
err = s.q.GetRequestingMessages.Select(&messages, userId, limit, offset)
}
case cs.StyleMsgUnread:
if err = s.q.CountUnreadMessages.Get(&total, userId); err == nil && total > 0 {
err = s.q.GetUnreadMessages.Select(&messages, userId, limit, offset)
}
case cs.StyleMsgAll:
fallthrough
default:
if err = s.q.CountAllMessages.Get(&total, userId, userId); err == nil && total > 0 {
err = s.q.GetAllMessages.Select(&messages, userId, userId, limit, offset)
}
} }
return mfs, nil if err == nil {
} for _, message := range messages {
res = append(res, message.Format())
func (s *messageSrv) GetMessageCount(userId int64) (res int64, err error) { }
if err = s.q.GetMessageCount.Get(&res, userId, userId); err != nil {
logrus.Errorf("get message count error: %s", err)
} }
return return
} }
func newMessageService(db *sqlx.DB) (s core.MessageService) { func newMessageService(db *sqlx.DB) (s core.MessageService) {

@ -20,17 +20,24 @@ type tweetMetricSrvA struct {
type commentMetricSrvA struct { type commentMetricSrvA struct {
*sqlxSrv *sqlxSrv
q *cc.CommentMetrics
} }
type userMetricSrvA struct { type userMetricSrvA struct {
*sqlxSrv *sqlxSrv
q *cc.UserMetrics
} }
func (s *tweetMetricSrvA) UpdateTweetMetric(metric *cs.TweetMetric) error { func (s *tweetMetricSrvA) UpdateTweetMetric(metric *cs.TweetMetric) error {
return s.db.Withx(func(tx *sqlx.Tx) error { return s.db.Withx(func(tx *sqlx.Tx) error {
var motivationFactor int var motivationFactor int
tx.Stmtx(s.q.GetMotivationFactor).Get(&motivationFactor, metric.PostId) now := time.Now().Unix()
_, err := tx.Stmtx(s.q.UpdateRankScore).Exec(metric.RankScore(motivationFactor), time.Now().Unix(), metric.PostId) err := tx.Stmtx(s.q.GetMotivationFactor).Get(&motivationFactor, metric.PostId)
if err == nil {
_, err = tx.Stmtx(s.q.UpdateRankScore).Exec(metric.RankScore(motivationFactor), now, metric.PostId)
} else {
_, err = tx.Stmtx(s.q.UpsertTweetMetric).Exec(metric.PostId, metric.RankScore(motivationFactor), now)
}
return err return err
}) })
} }
@ -46,33 +53,56 @@ func (s *tweetMetricSrvA) DeleteTweetMetric(postId int64) error {
} }
func (s *commentMetricSrvA) UpdateCommentMetric(metric *cs.CommentMetric) error { func (s *commentMetricSrvA) UpdateCommentMetric(metric *cs.CommentMetric) error {
// TDOO return s.db.Withx(func(tx *sqlx.Tx) error {
return cs.ErrNotImplemented var motivationFactor int
now := time.Now().Unix()
err := tx.Stmtx(s.q.GetMotivationFactor).Get(&motivationFactor, metric.CommentId)
if err == nil {
_, err = tx.Stmtx(s.q.UpdateRankScore).Exec(metric.RankScore(motivationFactor), now, metric.CommentId)
} else {
_, err = tx.Stmtx(s.q.UpsertCommentMetric).Exec(metric.CommentId, metric.RankScore(motivationFactor), now)
}
return err
})
} }
func (s *commentMetricSrvA) AddCommentMetric(commentId int64) (err error) { func (s *commentMetricSrvA) AddCommentMetric(commentId int64) error {
// TDOO _, err := s.q.AddCommentMetric.Exec(commentId, time.Now().Unix())
return cs.ErrNotImplemented return err
} }
func (s *commentMetricSrvA) DeleteCommentMetric(commentId int64) (err error) { func (s *commentMetricSrvA) DeleteCommentMetric(commentId int64) error {
// TDOO _, err := s.q.DeleteCommentMetric.Exec(time.Now().Unix(), commentId)
return cs.ErrNotImplemented return err
} }
func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) error { func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) (err error) {
// TODO var tweets_count int
return cs.ErrNotImplemented now := time.Now().Unix()
if err = s.q.GetTweetsCount.Get(&tweets_count, userId); err != nil {
_, err = s.q.AddUserMetric.Exec(userId, now)
return
}
switch action {
case cs.MetricActionCreateTweet:
tweets_count++
case cs.MetricActionDeleteTweet:
if tweets_count > 0 {
tweets_count--
}
}
_, err = s.q.UpdateUserMetric.Exec(userId, tweets_count)
return
} }
func (s *userMetricSrvA) AddUserMetric(userId int64) (err error) { func (s *userMetricSrvA) AddUserMetric(userId int64) error {
// TDOO _, err := s.q.AddUserMetric.Exec(userId, time.Now().Unix())
return cs.ErrNotImplemented return err
} }
func (s *userMetricSrvA) DeleteUserMetric(userId int64) (err error) { func (s *userMetricSrvA) DeleteUserMetric(userId int64) error {
// TDOO _, err := s.q.DeleteUserMetric.Exec(time.Now().Unix(), userId)
return cs.ErrNotImplemented return err
} }
func newTweetMetricServentA(db *sqlx.DB) core.TweetMetricServantA { func newTweetMetricServentA(db *sqlx.DB) core.TweetMetricServantA {
@ -85,11 +115,13 @@ func newTweetMetricServentA(db *sqlx.DB) core.TweetMetricServantA {
func newCommentMetricServentA(db *sqlx.DB) core.CommentMetricServantA { func newCommentMetricServentA(db *sqlx.DB) core.CommentMetricServantA {
return &commentMetricSrvA{ return &commentMetricSrvA{
sqlxSrv: newSqlxSrv(db), sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildCommentMetrics),
} }
} }
func newUserMetricServentA(db *sqlx.DB) core.UserMetricServantA { func newUserMetricServentA(db *sqlx.DB) core.UserMetricServantA {
return &userMetricSrvA{ return &userMetricSrvA{
sqlxSrv: newSqlxSrv(db), sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildUserMetrics),
} }
} }

@ -39,7 +39,9 @@ type dataSrv struct {
core.SecurityService core.SecurityService
core.AttachmentCheckService core.AttachmentCheckService
core.TweetMetricServantA core.TweetMetricServantA
core.UserMetricServantA
core.CommentMetricServantA core.CommentMetricServantA
core.TrendsManageServantA
} }
type webDataSrvA struct { type webDataSrvA struct {
@ -54,10 +56,13 @@ func NewDataService() (core.DataService, core.VersionInfo) {
pvs := security.NewPhoneVerifyService() pvs := security.NewPhoneVerifyService()
cms := newCommentMetricServentA(_db) cms := newCommentMetricServentA(_db)
tms := newTweetMetricServentA(_db) tms := newTweetMetricServentA(_db)
ums := newUserMetricServentA(_db)
cis := cache.NewEventCacheIndexSrv(tms) cis := cache.NewEventCacheIndexSrv(tms)
ds := &dataSrv{ ds := &dataSrv{
TweetMetricServantA: tms, TweetMetricServantA: tms,
CommentMetricServantA: cms, CommentMetricServantA: cms,
UserMetricServantA: ums,
TrendsManageServantA: newTrendsManageServentA(_db),
WalletService: newWalletService(_db), WalletService: newWalletService(_db),
MessageService: newMessageService(_db), MessageService: newMessageService(_db),
TopicService: newTopicService(_db), TopicService: newTopicService(_db),
@ -66,7 +71,7 @@ func NewDataService() (core.DataService, core.VersionInfo) {
TweetHelpService: newTweetHelpService(_db), TweetHelpService: newTweetHelpService(_db),
CommentService: newCommentService(_db), CommentService: newCommentService(_db),
CommentManageService: newCommentManageService(_db), CommentManageService: newCommentManageService(_db),
UserManageService: newUserManageService(_db), UserManageService: newUserManageService(_db, ums),
ContactManageService: newContactManageService(_db), ContactManageService: newContactManageService(_db),
UserRelationService: newUserRelationService(_db), UserRelationService: newUserRelationService(_db),
FollowingManageService: newFollowingManageService(_db), FollowingManageService: newFollowingManageService(_db),

@ -0,0 +1,31 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/bitbus/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc"
)
type trendsSrvA struct {
*sqlxSrv
q *cc.TrendsManager
}
func (s *trendsSrvA) GetIndexTrends(userId int64, limit int, offset int) (res []*cs.TrendsItem, total int64, err error) {
if err = s.q.CountIndexTrends.Get(&total, userId); err == nil && total > 0 {
err = s.q.GetIndexTrends.Select(&res, userId, limit, offset)
}
return
}
func newTrendsManageServentA(db *sqlx.DB) core.TrendsManageServantA {
return &trendsSrvA{
sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildTrendsManager),
}
}

@ -519,7 +519,7 @@ func (s *tweetSrv) getUserRelation(userId int64) (beFriendIds []int64, beFollowI
// 找到item即删数据库已经保证唯一性 // 找到item即删数据库已经保证唯一性
if beFollowIds[i] == id { if beFollowIds[i] == id {
lastIdx := len(beFollowIds) - 1 lastIdx := len(beFollowIds) - 1
beFriendIds[i] = beFriendIds[lastIdx] beFollowIds[i] = beFollowIds[lastIdx]
beFollowIds = beFollowIds[:lastIdx] beFollowIds = beFollowIds[:lastIdx]
break break
} }

@ -12,7 +12,6 @@ import (
"github.com/bitbus/sqlx" "github.com/bitbus/sqlx"
"github.com/bitbus/sqlx/db" "github.com/bitbus/sqlx/db"
"github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc" "github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc"
@ -24,11 +23,13 @@ var (
type userManageSrv struct { type userManageSrv struct {
*sqlxSrv *sqlxSrv
q *cc.UserManage q *cc.UserManage
ums core.UserMetricServantA
} }
type userRelationSrv struct { type userRelationSrv struct {
*sqlxSrv *sqlxSrv
q *cc.UserRelation
} }
func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) {
@ -69,7 +70,10 @@ func (s *userManageSrv) CreateUser(r *ms.User) (*ms.User, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
r.ID, err = res.LastInsertId() if r.ID, err = res.LastInsertId(); err == nil {
// 宽松处理错误
s.ums.AddUserMetric(r.ID)
}
return r, err return r, err
} }
@ -84,29 +88,64 @@ func (s *userManageSrv) GetRegisterUserCount() (res int64, err error) {
} }
func (s *userRelationSrv) MyFriendIds(userId int64) (res []int64, err error) { func (s *userRelationSrv) MyFriendIds(userId int64) (res []int64, err error) {
// TODO err = s.q.MyFriendIds.Select(&res, userId)
return return
} }
func (s *userRelationSrv) MyFollowIds(userId int64) (res []int64, err error) { func (s *userRelationSrv) MyFollowIds(userId int64) (res []int64, err error) {
// TODO err = s.q.MyFollowIds.Select(&res, userId)
return return
} }
func (s *userRelationSrv) IsMyFriend(userId int64, friendIds ...int64) (map[int64]bool, error) { func (s *userRelationSrv) IsMyFriend(userId int64, friendIds ...int64) (map[int64]bool, error) {
// TODO size := len(friendIds)
return nil, cs.ErrNotImplemented res := make(map[int64]bool, size)
if size == 0 {
return res, nil
}
myFriendIds, err := s.MyFriendIds(userId)
if err != nil {
return nil, err
}
for _, friendId := range friendIds {
res[friendId] = false
for _, myFriendId := range myFriendIds {
if friendId == myFriendId {
res[friendId] = true
break
}
}
}
return res, nil
} }
func (s *userRelationSrv) IsMyFollow(userId int64, followIds ...int64) (map[int64]bool, error) { func (s *userRelationSrv) IsMyFollow(userId int64, followIds ...int64) (map[int64]bool, error) {
// TODO size := len(followIds)
return nil, cs.ErrNotImplemented res := make(map[int64]bool, size)
if size == 0 {
return res, nil
}
myFollowIds, err := s.MyFollowIds(userId)
if err != nil {
return nil, err
}
for _, followId := range followIds {
res[followId] = false
for _, myFollowId := range myFollowIds {
if followId == myFollowId {
res[followId] = true
break
}
}
}
return res, nil
} }
func newUserManageService(db *sqlx.DB) (s core.UserManageService) { func newUserManageService(db *sqlx.DB, userMetric core.UserMetricServantA) (s core.UserManageService) {
ums := &userManageSrv{ ums := &userManageSrv{
sqlxSrv: newSqlxSrv(db), sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildUserManage), q: ccBuild(db, cc.BuildUserManage),
ums: userMetric,
} }
s = ums s = ums
if cfg.Any("PostgreSQL", "PgSQL", "Postgres") { if cfg.Any("PostgreSQL", "PgSQL", "Postgres") {
@ -121,5 +160,6 @@ func newUserManageService(db *sqlx.DB) (s core.UserManageService) {
func newUserRelationService(db *sqlx.DB) core.UserRelationService { func newUserRelationService(db *sqlx.DB) core.UserRelationService {
return &userRelationSrv{ return &userRelationSrv{
sqlxSrv: newSqlxSrv(db), sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildUserRelation),
} }
} }

@ -21,10 +21,11 @@ type pgcUserManageSrv struct {
p *pgc.UserManage p *pgc.UserManage
} }
func (s *pgcUserManageSrv) CreateUser(r *ms.User) (*ms.User, error) { func (s *pgcUserManageSrv) CreateUser(r *ms.User) (res *ms.User, err error) {
r.Model = &ms.Model{CreatedOn: time.Now().Unix()} res, r.Model = r, &ms.Model{CreatedOn: time.Now().Unix()}
if err := s.p.CreateUser.Get(&r.ID, r); err != nil { if err = s.p.CreateUser.Get(&r.ID, r); err == nil {
return nil, err // 宽松处理错误
s.ums.AddUserMetric(r.ID)
} }
return r, nil return
} }

@ -25,15 +25,29 @@ SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0;
-- name: get_newest_comments@comment -- name: get_newest_comments@comment
-- prepare: stmt -- prepare: stmt
SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?; SELECT *
FROM @comment
WHERE post_id=? AND is_del=0
ORDER BY is_essence DESC, id DESC
LIMIT ? OFFSET ?;
-- name: get_hots_comments@comment -- name: get_hots_comments@comment
-- prepare: stmt -- prepare: stmt
SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY thumbs_up_count DESC, id DESC LIMIT ? OFFSET ?; SELECT c.*
FROM @comment c
LEFT JOIN @comment_metric m
ON c.id=m.comment_id
WHERE c.post_id=? AND c.is_del=0 AND m.is_del=0
ORDER BY is_essence DESC, m.rank_score DESC, id DESC
LIMIT ? OFFSET ?;
-- name: get_default_comments@comment -- name: get_default_comments@comment
-- prepare: stmt -- prepare: stmt
SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY id ASC LIMIT ? OFFSET ?; SELECT *
FROM @comment
WHERE post_id=? AND is_del=0
ORDER BY is_essence DESC, id ASC
LIMIT ? OFFSET ?;
-- name: get_comment_by_id@comment -- name: get_comment_by_id@comment
-- prepare: stmt -- prepare: stmt
@ -97,6 +111,20 @@ VALUES (?, ?, ?, ?, ?);
INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on)
VALUES (?, ?, ?, ?, ?, ?, ?); VALUES (?, ?, ?, ?, ?, ?, ?);
-- name: incr_comment_reply_count@comment_manage
-- prepare: stmt
UPDATE @comment
SET reply_count=reply_count+1,
modified_on=?
WHERE id=? AND is_del=0;
-- name: decr_comment_reply_count@comment_manage
-- prepare: stmt
UPDATE @comment
SET reply_count=reply_count-1,
modified_on=?
WHERE id=? AND is_del=0;
-- name: delete_comment_reply@comment_manage -- name: delete_comment_reply@comment_manage
-- prepare: stmt -- prepare: stmt
UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0;
@ -197,6 +225,41 @@ LIMIT ? OFFSET ?;
-- prepare: stmt -- prepare: stmt
SELECT count(*) FROM @following WHERE follow_id=? AND is_del=0; SELECT count(*) FROM @following WHERE follow_id=? AND is_del=0;
--------------------------------------------------------------------------------
-- trends_manager sql dml
--------------------------------------------------------------------------------
-- name: get_index_trends@trends_manager
-- prepare: stmt
SELECT u.username username,
u.nickname nickname,
u.avatar avatar
FROM @contact c
JOIN @user u
ON c.friend_id=u.id
JOIN @user_metric m
ON c.friend_id=m.user_id
WHERE c.user_id=?
AND c.is_del=0
AND u.is_del=0
AND m.is_del=0
AND m.tweets_count>0
LIMIT ? OFFSET ?;
-- name: count_index_trends@trends_manager
-- prepare: stmt
SELECT count(*)
FROM @contact c
JOIN @user u
ON c.friend_id=u.id
JOIN @user_metric m
ON c.friend_id=m.user_id
WHERE c.user_id=?
AND c.is_del=0
AND u.is_del=0
AND m.is_del=0
AND m.tweets_count>0;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- contact_manager sql dml -- contact_manager sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -288,17 +351,75 @@ SELECT * FROM @message WHERE id=? AND is_del=0;
-- prepare: stmt -- prepare: stmt
UPDATE @message SET is_read=1, modified_on=? WHERE id=?; UPDATE @message SET is_read=1, modified_on=? WHERE id=?;
-- name: get_messages@message -- name: get_system_messages@message
-- prepare: stmt
SELECT *
FROM @message
WHERE receiver_user_id=? AND type IN (1, 2, 3, 99) AND is_del=0
ORDER BY id DESC
LIMIT ? OFFSET ?;
-- name: count_system_messages@message
-- prepare: stmt
SELECT count(*)
FROM @message
WHERE receiver_user_id=? AND type IN (1, 2, 3, 99) AND is_del=0;
-- name: get_whisper_messages@message
-- prepare: stmt
SELECT *
FROM @message
WHERE ((receiver_user_id=? OR sender_user_id=?) AND type=4) AND is_del=0
ORDER BY id DESC
LIMIT ? OFFSET ?;
-- name: count_whisper_messages@message
-- prepare: stmt
SELECT count(*)
FROM @message
WHERE ((receiver_user_id=? OR sender_user_id=?) AND type=4) AND is_del=0;
-- name: get_requesting_messages@message
-- prepare: stmt
SELECT *
FROM @message
WHERE receiver_user_id=? AND type=5 AND is_del=0
ORDER BY id DESC
LIMIT ? OFFSET ?;
-- name: count_requesting_messages@message
-- prepare: stmt
SELECT count(*)
FROM @message
WHERE receiver_user_id=? AND type=5 AND is_del=0;
-- name: get_unread_messages@message
-- prepare: stmt
SELECT *
FROM @message
WHERE receiver_user_id=? AND is_read=0 AND is_del=0
ORDER BY id DESC
LIMIT ? OFFSET ?;
-- name: count_unread_messages@message
-- prepare: stmt
SELECT count(*)
FROM @message
WHERE receiver_user_id=? AND is_read=0 AND is_del=0;
-- name: get_all_messages@message
-- prepare: stmt -- prepare: stmt
SELECT * SELECT *
FROM @message FROM @message
WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0 WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0
ORDER BY id DESC ORDER BY id DESC
LIMIT ? OFFSET ? LIMIT ? OFFSET ?;
-- name: get_message_count@message -- name: count_all_messages@message
-- prepare: stmt -- prepare: stmt
SELECT count(*) FROM @message WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0 SELECT count(*)
FROM @message
WHERE (receiver_user_id=? OR (sender_user_id=? AND type=4)) AND is_del=0;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- security sql dml -- security sql dml
@ -1191,6 +1312,7 @@ WHERE id IN (?) AND is_del=0;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- tweet_metrics sql dml -- tweet_metrics sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- name: update_rank_score@tweet_metrics -- name: update_rank_score@tweet_metrics
-- prepare: stmt -- prepare: stmt
UPDATE @post_metric SET rank_score=?, modified_on=? WHERE post_id=? AND is_del=0; UPDATE @post_metric SET rank_score=?, modified_on=? WHERE post_id=? AND is_del=0;
@ -1203,10 +1325,58 @@ SELECT motivation_factor FROM @post_metric WHERE post_id=? AND is_del=0;
-- prepare: stmt -- prepare: stmt
INSERT INTO @post_metric (post_id, created_on) VALUES (?, ?); INSERT INTO @post_metric (post_id, created_on) VALUES (?, ?);
-- name: upsert_tweet_metric@tweet_metrics
-- prepare: stmt
INSERT INTO @post_metric (post_id, rank_score, created_on) VALUES (?, ?, ?);
-- name: delete_tweet_metric@tweet_metrics -- name: delete_tweet_metric@tweet_metrics
-- prepare: stmt -- prepare: stmt
UPDATE @post_metric SET is_del=1, deleted_on=? WHERE post_id=? AND is_del=0; UPDATE @post_metric SET is_del=1, deleted_on=? WHERE post_id=? AND is_del=0;
--------------------------------------------------------------------------------
-- comment_metrics sql dml
--------------------------------------------------------------------------------
-- name: update_rank_score@comment_metrics
-- prepare: stmt
UPDATE @comment_metric SET rank_score=?, modified_on=? WHERE comment_id=? AND is_del=0;
-- name: get_motivation_factor@comment_metrics
-- prepare: stmt
SELECT motivation_factor FROM @comment_metric WHERE comment_id=? AND is_del=0;
-- name: add_comment_metric@comment_metrics
-- prepare: stmt
INSERT INTO @comment_metric (comment_id, created_on) VALUES (?, ?);
-- name: upsert_comment_metric@comment_metrics
-- prepare: stmt
INSERT INTO @comment_metric (comment_id, rank_score, created_on) VALUES (?, ?, ?);
-- name: delete_comment_metric@comment_metrics
-- prepare: stmt
UPDATE @comment_metric SET is_del=1, deleted_on=? WHERE comment_id=? AND is_del=0;
--------------------------------------------------------------------------------
-- user_metrics sql dml
--------------------------------------------------------------------------------
-- name: update_user_metric@user_metrics
-- prepare: stmt
UPDATE @user_metric SET tweets_count=?, modified_on=? WHERE user_id=? AND is_del=0;
-- name: get_tweets_count@user_metrics
-- prepare: stmt
SELECT tweets_count FROM @user_metric WHERE user_id=? AND is_del=0;
-- name: add_user_metric@user_metrics
-- prepare: stmt
INSERT INTO @user_metric (user_id, created_on) VALUES (?, ?);
-- name: delete_user_metric@user_metrics
-- prepare: stmt
UPDATE @user_metric SET is_del=1, deleted_on=? WHERE user_id=? AND is_del=0;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- user_manage sql dml -- user_manage sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -1260,6 +1430,18 @@ SET username=:username,
modified_on=:modified_on modified_on=:modified_on
WHERE id=? AND is_del=0; WHERE id=? AND is_del=0;
--------------------------------------------------------------------------------
-- user_relation sql dml
--------------------------------------------------------------------------------
-- name: my_friend_ids@user_relation
-- prepare: stmt
SELECT friend_id FROM @contact WHERE user_id=? AND is_del=0;
-- name: my_follow_ids@user_relation
-- prepare: stmt
SELECT follow_id FROM @following WHERE user_id=? AND is_del=0;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- wallet sql dml -- wallet sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

@ -52,6 +52,20 @@ INSERT INTO @post_collection (post_id, user_id, created_on)
VALUES (?, ?, ?) VALUES (?, ?, ?)
RETURNING *; RETURNING *;
--------------------------------------------------------------------------------
-- comment sql dml
--------------------------------------------------------------------------------
-- name: get_hots_comments@comment
-- prepare: stmt
SELECT c.*
FROM @comment c
LEFT JOIN @comment_metric m
ON c.id=m.comment_id
WHERE c.post_id=? AND c.is_del=0 AND m.is_del=0
ORDER BY is_essence DESC, m.rank_score DESC NULLS LAST, id DESC
LIMIT ? OFFSET ?;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- user_manage sql dml -- user_manage sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

Loading…
Cancel
Save