diff --git a/go.mod b/go.mod index 730c2282..cb5f0fdf 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 github.com/alimy/cfg v0.3.0 github.com/alimy/mir/v3 v3.1.1 - github.com/alimy/yesql v1.1.5 + github.com/alimy/yesql v1.1.6 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible github.com/allegro/bigcache/v3 v3.0.2 github.com/bytedance/sonic v1.8.7 diff --git a/go.sum b/go.sum index 4f2b7dea..11a6fd67 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,8 @@ github.com/alimy/cfg v0.3.0 h1:9xgA0QWVCPSq9fFNRcYahVCAX22IL9ts2wrTQPfAStY= github.com/alimy/cfg v0.3.0/go.mod h1:rOxbasTH2srl6StAjNF5Vyi8bfrdkl3fLGmOYtSw81c= github.com/alimy/mir/v3 v3.1.1 h1:3tz7uGOwuA1IKU0BysyBvGbyqKtEVMuhPBD/APk1ANw= github.com/alimy/mir/v3 v3.1.1/go.mod h1:ybhT2ijOiDn0lLwWzIY6vXdv+uzZrctS7VFfczcXBWU= -github.com/alimy/yesql v1.1.5 h1:kHqF5rXS8if/YXazXyfo2OjqV+NhkvVwR43+dfkxkKU= -github.com/alimy/yesql v1.1.5/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= +github.com/alimy/yesql v1.1.6 h1:4on8osVaTpecfzf7gXM/1okyHMIaDKEkjHGdoqiZBQs= +github.com/alimy/yesql v1.1.6/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible h1:KpbJFXwhVeuxNtBJ74MCGbIoaBok2uZvkD7QXp2+Wis= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v3 v3.0.2 h1:AKZCw+5eAaVyNTBmI2fgyPVJhHkdWder3O9IrprcQfI= diff --git a/internal/dao/sakila/sakila.go b/internal/dao/sakila/sakila.go index 0ad570ed..a232424b 100644 --- a/internal/dao/sakila/sakila.go +++ b/internal/dao/sakila/sakila.go @@ -9,6 +9,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/alimy/cfg" + "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/dao/cache" "github.com/rocboss/paopao-ce/internal/dao/security" @@ -112,8 +113,55 @@ func NewDataService() (core.DataService, core.VersionInfo) { func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) { lazyInitial() - // db := conf.MustSqlxDB() - ds := &webDataSrvA{} + + var ( + v core.VersionInfo + cis core.CacheIndexService + ips core.IndexPostsService + ) + // pvs := security.NewPhoneVerifyService() + ams := NewAuthorizationManageService() + ths := newTweetHelpService(_db) + + // initialize core.IndexPostsService + if cfg.If("Friendship") { + ips = newFriendIndexService(_db, ams, ths) + } else if cfg.If("Followship") { + ips = newFollowIndexService(_db, ths) + } else if cfg.If("Lightship") { + ips = newLightIndexService(_db, ths) + } else { + // default use lightship post index service + ips = newLightIndexService(_db, ths) + } + + // initialize core.CacheIndexService + cfg.On(cfg.Actions{ + "SimpleCacheIndex": func() { + // simpleCache use special post index service + ips = newSimpleIndexPostsService(_db, ths) + cis, v = cache.NewSimpleCacheIndexService(ips) + }, + "BigCacheIndex": func() { + // TODO: make cache index post in different scence like friendship/followship/lightship + cis, v = cache.NewBigCacheIndexService(ips, ams) + }, + "RedisCacheIndex": func() { + cis, v = cache.NewRedisCacheIndexService(ips, ams) + }, + }, func() { + // defualt no cache + cis, v = cache.NewNoneCacheIndexService(ips) + }) + logrus.Infof("use %s as cache index service by version: %s", v.Name(), v.Version()) + + db := conf.MustSqlxDB() + ds := &webDataSrvA{ + TopicServantA: newTopicServantA(db), + TweetServantA: newTweetServantA(db), + TweetManageServantA: newTweetManageServantA(db, cis), + TweetHelpServantA: newTweetHelpServantA(db), + } return ds, ds } @@ -135,7 +183,7 @@ func (s *webDataSrvA) Name() string { } func (s *webDataSrvA) Version() *semver.Version { - return semver.MustParse("v0.0.0") + return semver.MustParse("v0.0.1") } // lazyInitial do some package lazy initialize for performance diff --git a/internal/dao/sakila/sakila_suite_test.go b/internal/dao/sakila/sakila_suite_test.go index 15a529fd..856b51fc 100644 --- a/internal/dao/sakila/sakila_suite_test.go +++ b/internal/dao/sakila/sakila_suite_test.go @@ -1,3 +1,7 @@ +// 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_test import ( diff --git a/internal/dao/sakila/sqlx_test.go b/internal/dao/sakila/sqlx_test.go index 98947a9f..25502f38 100644 --- a/internal/dao/sakila/sqlx_test.go +++ b/internal/dao/sakila/sqlx_test.go @@ -1,3 +1,7 @@ +// 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_test import ( diff --git a/internal/dao/sakila/timeline.go b/internal/dao/sakila/timeline.go index e8d39249..1c5d3016 100644 --- a/internal/dao/sakila/timeline.go +++ b/internal/dao/sakila/timeline.go @@ -17,6 +17,11 @@ var ( _ core.IndexPostsService = (*followIndexSrv)(nil) _ core.IndexPostsService = (*lightIndexSrv)(nil) _ core.IndexPostsService = (*simpleIndexPostsSrv)(nil) + + _ core.IndexPostsServantA = (*friendIndexSrvA)(nil) + _ core.IndexPostsServantA = (*followIndexSrvA)(nil) + _ core.IndexPostsServantA = (*lightIndexSrvA)(nil) + _ core.IndexPostsServantA = (*simpleIndexPostsSrvA)(nil) ) type friendIndexSrv struct { @@ -44,46 +49,75 @@ type simpleIndexPostsSrv struct { q *cc.SimpleIndex } +type friendIndexSrvA struct { + *sqlxSrv + ams core.AuthorizationManageService + ths core.TweetHelpServantA + q *cc.FriendIndexA +} + +type followIndexSrvA struct { + *sqlxSrv + ths core.TweetHelpServantA + q *cc.FollowIndexA +} + +type lightIndexSrvA struct { + *sqlxSrv + ths core.TweetHelpServantA + q *cc.LightIndexA +} + +type simpleIndexPostsSrvA struct { + *sqlxSrv + ths core.TweetHelpServantA + q *cc.SimpleIndexA +} + // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *friendIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { +// IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; +func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *followIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { +// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 +func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *friendIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *lightIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { +// IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; +func (s *followIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } -// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +// IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; +func (s *lightIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *simpleIndexPostsSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { +// IndexPosts simpleCacheIndex 专属获取广场推文列表函数 +func (s *simpleIndexPostsSrvA) IndexPosts(_user *core.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } @@ -91,6 +125,7 @@ func (s *simpleIndexPostsSrv) TweetTimeline(userId int64, offset int, limit int) func newFriendIndexService(db *sqlx.DB, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService { return &friendIndexSrv{ ams: ams, + ths: ths, sqlxSrv: newSqlxSrv(db), q: mustBuild(db, cc.BuildFriendIndex), } @@ -119,3 +154,36 @@ func newSimpleIndexPostsService(db *sqlx.DB, ths core.TweetHelpService) core.Ind q: mustBuild(db, cc.BuildSimpleIndex), } } + +func newFriendIndexServantA(db *sqlx.DB, ams core.AuthorizationManageService, ths core.TweetHelpServantA) core.IndexPostsServantA { + return &friendIndexSrvA{ + ams: ams, + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildFriendIndexA), + } +} + +func newFollowIndexServantA(db *sqlx.DB, ths core.TweetHelpServantA) core.IndexPostsServantA { + return &followIndexSrvA{ + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildFollowIndexA), + } +} + +func newLightIndexServantA(db *sqlx.DB, ths core.TweetHelpServantA) core.IndexPostsServantA { + return &lightIndexSrvA{ + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildLightIndexA), + } +} + +func newSimpleIndexPostsServantA(db *sqlx.DB, ths core.TweetHelpServantA) core.IndexPostsServantA { + return &simpleIndexPostsSrvA{ + ths: ths, + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildSimpleIndexA), + } +} diff --git a/internal/dao/sakila/topics.go b/internal/dao/sakila/topics.go index 93feeeca..1f00ea6d 100644 --- a/internal/dao/sakila/topics.go +++ b/internal/dao/sakila/topics.go @@ -15,15 +15,16 @@ import ( ) var ( - _ core.TopicService = (*topicSrv)(nil) + _ core.TopicService = (*topicSrvA)(nil) + _ core.TopicServantA = (*topicSrvA)(nil) ) -type topicSrv struct { +type topicSrvA struct { *sqlxSrv - q *cc.Topic + q *cc.TopicA } -func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, xerr error) { +func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, xerr error) { if len(tags) == 0 { return nil, nil } @@ -80,7 +81,7 @@ func (s *topicSrv) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, return } -func (s *topicSrv) DecrTagsById(ids []int64) error { +func (s *topicSrvA) DecrTagsById(ids []int64) error { return s.with(func(tx *sqlx.Tx) error { var ids []int64 err := s.inSelect(tx, &ids, s.q.TagsByIdA, ids) @@ -92,7 +93,7 @@ func (s *topicSrv) DecrTagsById(ids []int64) error { }) } -func (s *topicSrv) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagList, err error) { +func (s *topicSrvA) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagList, err error) { switch typ { case cs.TagTypeHot: err = s.q.HotTags.Select(&res, limit, offset) @@ -102,7 +103,7 @@ func (s *topicSrv) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagLi return } -func (s *topicSrv) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) { +func (s *topicSrvA) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) { keyword = "%" + strings.Trim(keyword, " ") + "%" if keyword == "%%" { err = s.q.TagsByKeywordA.Select(&res) @@ -113,8 +114,15 @@ func (s *topicSrv) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) } func newTopicService(db *sqlx.DB) core.TopicService { - return &topicSrv{ + return &topicSrvA{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildTopic), + q: mustBuild(db, cc.BuildTopicA), + } +} + +func newTopicServantA(db *sqlx.DB) core.TopicServantA { + return &topicSrvA{ + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildTopicA), } } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index 509802cd..f97d0cc6 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -11,13 +11,16 @@ import ( "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" - "gorm.io/gorm" ) var ( _ core.TweetService = (*tweetSrv)(nil) _ core.TweetManageService = (*tweetManageSrv)(nil) _ core.TweetHelpService = (*tweetHelpSrv)(nil) + + _ core.TweetServantA = (*tweetSrvA)(nil) + _ core.TweetManageServantA = (*tweetManageSrvA)(nil) + _ core.TweetHelpServantA = (*tweetHelpSrvA)(nil) ) type tweetSrv struct { @@ -27,8 +30,8 @@ type tweetSrv struct { type tweetManageSrv struct { *sqlxSrv - cacheIndex core.CacheIndexService - q *cc.TweetManage + cis core.CacheIndexService + q *cc.TweetManage } type tweetHelpSrv struct { @@ -36,6 +39,22 @@ type tweetHelpSrv struct { q *cc.TweetHelp } +type tweetSrvA struct { + *sqlxSrv + q *cc.TweetA +} + +type tweetManageSrvA struct { + *sqlxSrv + cis core.CacheIndexService + q *cc.TweetManageA +} + +type tweetHelpSrvA struct { + *sqlxSrv + q *cc.TweetHelpA +} + // MergePosts post数据整合 func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { // TODO @@ -50,16 +69,6 @@ func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostForm return nil, nil } -func (s *tweetHelpSrv) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetHelpSrv) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) { - // TODO - return nil, debug.ErrNotImplemented -} - func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) { // TODO debug.NotImplemented() @@ -107,12 +116,6 @@ func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) { return nil, nil } -func (s *tweetManageSrv) deleteCommentByPostId(db *gorm.DB, postId int64) ([]string, error) { - // TODO - debug.NotImplemented() - return nil, nil -} - func (s *tweetManageSrv) LockPost(post *core.Post) error { // TODO debug.NotImplemented() @@ -149,51 +152,6 @@ func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error { return nil } -func (s *tweetManageSrv) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetManageSrv) DeleteTweet(userId int64, tweetId int64) ([]string, error) { - // TODO - return nil, debug.ErrNotImplemented -} - -func (s *tweetManageSrv) LockTweet(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrv) StickTweet(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrv) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrv) CreateReaction(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrv) DeleteReaction(userId int64, reactionId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrv) CreateFavorite(userId int64, tweetId int64) error { - // TODO - return debug.ErrNotImplemented -} - -func (s *tweetManageSrv) DeleteFavorite(userId int64, favoriteId int64) error { - // TODO - return debug.ErrNotImplemented -} - func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { // TODO debug.NotImplemented() @@ -278,42 +236,102 @@ func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) { return nil, nil } -func (s *tweetSrv) TweetInfoById(id int64) (*cs.TweetInfo, error) { +func (s *tweetSrvA) TweetInfoById(id int64) (*cs.TweetInfo, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) TweetItemById(id int64) (*cs.TweetItem, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) UserTweets(visitorId, userId int64) (cs.TweetList, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) { + // TODO + return nil, debug.ErrNotImplemented +} + +func (s *tweetSrvA) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) TweetItemById(id int64) (*cs.TweetItem, error) { +func (s *tweetSrvA) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) UserTweets(visitorId, userId int64) (cs.TweetList, error) { +func (s *tweetSrvA) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) { +func (s *tweetSrvA) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error) { +func (s *tweetManageSrvA) CreateAttachment(obj *cs.Attachment) (int64, error) { + // TODO + return 0, debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) { +func (s *tweetManageSrvA) DeleteTweet(userId int64, tweetId int64) ([]string, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error) { +func (s *tweetManageSrvA) LockTweet(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) StickTweet(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateReaction(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) DeleteReaction(userId int64, reactionId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) CreateFavorite(userId int64, tweetId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetManageSrvA) DeleteFavorite(userId int64, favoriteId int64) error { + // TODO + return debug.ErrNotImplemented +} + +func (s *tweetHelpSrvA) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) { // TODO return nil, debug.ErrNotImplemented } -func (s *tweetSrv) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) { +func (s *tweetHelpSrvA) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) { // TODO return nil, debug.ErrNotImplemented } @@ -327,9 +345,9 @@ func newTweetService(db *sqlx.DB) core.TweetService { func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageService { return &tweetManageSrv{ - sqlxSrv: newSqlxSrv(db), - cacheIndex: cacheIndex, - q: mustBuild(db, cc.BuildTweetManage), + sqlxSrv: newSqlxSrv(db), + cis: cacheIndex, + q: mustBuild(db, cc.BuildTweetManage), } } @@ -339,3 +357,25 @@ func newTweetHelpService(db *sqlx.DB) core.TweetHelpService { q: mustBuild(db, cc.BuildTweetHelp), } } + +func newTweetServantA(db *sqlx.DB) core.TweetServantA { + return &tweetSrvA{ + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildTweetA), + } +} + +func newTweetManageServantA(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageServantA { + return &tweetManageSrvA{ + sqlxSrv: newSqlxSrv(db), + cis: cacheIndex, + q: mustBuild(db, cc.BuildTweetManageA), + } +} + +func newTweetHelpServantA(db *sqlx.DB) core.TweetHelpServantA { + return &tweetHelpSrvA{ + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildTweetHelpA), + } +} diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index b2423f88..5ca84383 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -1,6 +1,6 @@ // Code generated by Yesql. DO NOT EDIT. // versions: -// - Yesql v1.1.5 +// - Yesql v1.1.6 package cc @@ -12,31 +12,38 @@ import ( ) const ( - _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` - _NewestTags_Topic = `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 ?` - _TagsByKeywordA_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TagsByKeywordB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TagsByIdB_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _HotTags_Topic = `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 ?` - _InsertTag_Topic = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _TagsByIdA_Topic = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _DecrTagsById_Topic = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _TagsForIncr_Topic = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _IncrTagsById_Topic = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _UserInfo_Wallet = `SELECT * FROM @user WHERE username=?` + _UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Comment = `SELECT * FROM @user WHERE username=?` _UserInfo_ContactManager = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_UserManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_Message = `SELECT * FROM @user WHERE username=?` _UserInfo_Security = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` + _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _HotTags_TopicA = `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 ?` + _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _NewestTags_TopicA = `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 ?` + _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` _UserInfo_TweetHelp = `SELECT * FROM @user WHERE username=?` - _UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_Comment = `SELECT * FROM @user WHERE username=?` - _UserInfo_Message = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_Tweet = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` _UserInfo_TweetManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Tweet = `SELECT * FROM @user WHERE username=?` + _UserInfo_UserManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Wallet = `SELECT * FROM @user WHERE username=?` ) type AuthorizationManage struct { @@ -64,16 +71,31 @@ type FollowIndex struct { UserInfo *sqlx.Stmt `yesql:"user_info"` } +type FollowIndexA struct { + yesql.Namespace `yesql:"follow_index_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type FriendIndex struct { yesql.Namespace `yesql:"friend_index"` UserInfo *sqlx.Stmt `yesql:"user_info"` } +type FriendIndexA struct { + yesql.Namespace `yesql:"friend_index_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type LightIndex struct { yesql.Namespace `yesql:"light_index"` UserInfo *sqlx.Stmt `yesql:"user_info"` } +type LightIndexA struct { + yesql.Namespace `yesql:"light_index_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type Message struct { yesql.Namespace `yesql:"message"` UserInfo *sqlx.Stmt `yesql:"user_info"` @@ -89,8 +111,13 @@ type SimpleIndex struct { UserInfo *sqlx.Stmt `yesql:"user_info"` } -type Topic struct { - yesql.Namespace `yesql:"topic"` +type SimpleIndexA struct { + yesql.Namespace `yesql:"simple_index_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + +type TopicA struct { + yesql.Namespace `yesql:"topic_a"` DecrTagsById string `yesql:"decr_tags_by_id"` IncrTagsById string `yesql:"incr_tags_by_id"` TagsByIdA string `yesql:"tags_by_id_a"` @@ -108,16 +135,31 @@ type Tweet struct { UserInfo *sqlx.Stmt `yesql:"user_info"` } +type TweetA struct { + yesql.Namespace `yesql:"tweet_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type TweetHelp struct { yesql.Namespace `yesql:"tweet_help"` UserInfo *sqlx.Stmt `yesql:"user_info"` } +type TweetHelpA struct { + yesql.Namespace `yesql:"tweet_help_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type TweetManage struct { yesql.Namespace `yesql:"tweet_manage"` UserInfo *sqlx.Stmt `yesql:"user_info"` } +type TweetManageA struct { + yesql.Namespace `yesql:"tweet_manage_a"` + UserInfo *sqlx.Stmt `yesql:"user_info"` +} + type UserManage struct { yesql.Namespace `yesql:"user_manage"` UserInfo *sqlx.Stmt `yesql:"user_info"` @@ -198,6 +240,20 @@ func BuildFollowIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fol return } +func BuildFollowIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FollowIndexA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &FollowIndexA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FollowIndexA))); err != nil { + return + } + return +} + func BuildFriendIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FriendIndex, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -212,6 +268,20 @@ func BuildFriendIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fri return } +func BuildFriendIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FriendIndexA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &FriendIndexA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FriendIndexA))); err != nil { + return + } + return +} + func BuildLightIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *LightIndex, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -226,6 +296,20 @@ func BuildLightIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Ligh return } +func BuildLightIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *LightIndexA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &LightIndexA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_LightIndexA))); err != nil { + return + } + return +} + func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -268,33 +352,47 @@ func BuildSimpleIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Sim return } -func BuildTopic(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Topic, err error) { +func BuildSimpleIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *SimpleIndexA, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { c = ctx[0] } else { c = context.Background() } - obj = &Topic{ - DecrTagsById: p.QueryHook(_DecrTagsById_Topic), - IncrTagsById: p.QueryHook(_IncrTagsById_Topic), - TagsByIdA: p.QueryHook(_TagsByIdA_Topic), - TagsByIdB: p.QueryHook(_TagsByIdB_Topic), - TagsForIncr: p.QueryHook(_TagsForIncr_Topic), + obj = &SimpleIndexA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_SimpleIndexA))); err != nil { + return } - if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HotTags_Topic))); err != nil { + return +} + +func BuildTopicA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TopicA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TopicA{ + DecrTagsById: p.QueryHook(_DecrTagsById_TopicA), + IncrTagsById: p.QueryHook(_IncrTagsById_TopicA), + TagsByIdA: p.QueryHook(_TagsByIdA_TopicA), + TagsByIdB: p.QueryHook(_TagsByIdB_TopicA), + TagsForIncr: p.QueryHook(_TagsForIncr_TopicA), + } + if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HotTags_TopicA))); err != nil { return } - if obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_InsertTag_Topic))); err != nil { + if obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_InsertTag_TopicA))); err != nil { return } - if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewestTags_Topic))); err != nil { + if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewestTags_TopicA))); err != nil { return } - if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordA_Topic))); err != nil { + if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordA_TopicA))); err != nil { return } - if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordB_Topic))); err != nil { + if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordB_TopicA))); err != nil { return } return @@ -314,6 +412,20 @@ func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, er return } +func BuildTweetA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TweetA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetA))); err != nil { + return + } + return +} + func BuildTweetHelp(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetHelp, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -328,6 +440,20 @@ func BuildTweetHelp(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet return } +func BuildTweetHelpA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetHelpA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TweetHelpA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetHelpA))); err != nil { + return + } + return +} + func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -342,6 +468,20 @@ func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twe return } +func BuildTweetManageA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetManageA, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &TweetManageA{} + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetManageA))); err != nil { + return + } + return +} + func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *UserManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index e14e18d2..ae78b357 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -78,6 +78,38 @@ SELECT * FROM @user WHERE username=? -- prepare: stmt SELECT * FROM @user WHERE username=? +-------------------------------------------------------------------------------- +-- friend_index_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@friend_index_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- follow_index_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@follow_index_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- light_index_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@light_index_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- simple_index_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@simple_index_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + -------------------------------------------------------------------------------- -- tweet sql dml -------------------------------------------------------------------------------- @@ -103,10 +135,34 @@ SELECT * FROM @user WHERE username=? SELECT * FROM @user WHERE username=? -------------------------------------------------------------------------------- --- topic sql dml +-- tweet_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_manage_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_manage_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- tweet_help_a sql dml +-------------------------------------------------------------------------------- + +-- name: user_info@tweet_help_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-------------------------------------------------------------------------------- +-- topic_a sql dml -------------------------------------------------------------------------------- --- name: newest_tags@topic +-- name: newest_tags@topic_a -- get newest tag information 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 @@ -116,7 +172,7 @@ WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?; --- name: hot_tags@topic +-- name: hot_tags@topic_a -- get get host tag information 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 @@ -126,37 +182,37 @@ WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?; --- name: tags_by_keyword_a@topic +-- name: tags_by_keyword_a@topic_a -- get tags by keyword SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6; --- name: tags_by_keyword_b@topic +-- name: tags_by_keyword_b@topic_a SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6; --- name: insert_tag@topic +-- name: insert_tag@topic_a INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1); --- name: tags_by_id_a@topic +-- name: tags_by_id_a@topic_a -- prepare: raw -- clause: in SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0; --- name: tags_by_id_b@topic +-- name: tags_by_id_b@topic_a -- prepare: raw -- clause: in SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?); --- name: decr_tags_by_id@topic +-- name: decr_tags_by_id@topic_a -- prepare: raw -- clause: in UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?); --- name: tags_for_incr@topic +-- name: tags_for_incr@topic_a -- prepare: raw -- clause: in SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?); --- name: incr_tags_by_id@topic +-- name: incr_tags_by_id@topic_a -- prepare: raw -- clause: in UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?);