blog/bootstrap/InitData.go

72 lines
2.4 KiB
Go

package bootstrap
// import (
// "Blog/internal/client"
// "Blog/internal/consts"
// "Blog/internal/model"
// "Blog/internal/repository"
// "context"
// "time"
// red "github.com/redis/go-redis/v9"
// "github.com/sirupsen/logrus"
// )
// func InitData() {
// initArticleData()
// // initDiaryData()
// // initContentData()
// // initViewRecordData()
// }
// func initArticleData() {
// var slices []model.BlogArticle = repository.ArticleRep.FindList(nil, "state = ?", consts.ARTICLE_STATE_PUBLISH)
// logrus.Info("文章初始化数据加载量:", len(slices))
// ctx := context.Background()
// for _, article := range slices {
// // logrus.Info(article)
// publishTime := article.PublishTime
// err := client.RedisClient().ZAdd(ctx, consts.REDIS_BLOG_ARTICLE_LATEST, red.Z{Score: float64(publishTime), Member: &article}).Err()
// if err != nil {
// logrus.Info(err)
// }
// }
// }
// func initDiaryData() {
// // bd := repository.DiaryRepository.BaseRep().Get("")
// var slices []model.BlogDiary = repository.DiaryRep.FindList(nil)
// // result := repository.DiaryRepository.DB.Gorm.Table(consts.TABLE_BLOG_DIARY).Find(&diarySlice)
// logrus.Info("日记初始化数据加载量:", len(slices))
// ctx := context.Background()
// for _, diary := range slices {
// // logrus.Info(article)
// publishTime := diary.PublishTime
// err := client.RedisClient().ZAdd(ctx, consts.REDIS_BLOG_DIARY_LATEST, red.Z{Score: float64(publishTime), Member: &diary}).Err()
// if err != nil {
// logrus.Info(err)
// }
// }
// }
// func initContentData() {
// var slices []model.BlogTextContent = repository.TextContentRep.FindList(nil, "state = ?", consts.CONTENT_STATE_PUBLISH)
// logrus.Info("大文本初始化数据加载量:", len(slices))
// for _, content := range slices {
// client.RedisClient().Set(context.Background(), consts.REDIS_BLOG_CONTENT+content.RelId, &content, time.Duration(0))
// }
// }
// func initViewRecordData() {
// type viewRecord struct {
// RelId string
// Counts int
// }
// var slices []viewRecord
// repository.ViewRecordRep().Table(consts.TABLE_BLOG_VIEW_RECORD).Select("rel_id ,count(1) counts").Group("rel_id").Find(&slices)
// logrus.Info("点击量初始化数据加载量:", len(slices))
// for _, val := range slices {
// client.RedisClient().HSet(context.Background(), consts.REDIS_BLOG_VIEW_RECORD, map[string]any{val.RelId: val.Counts})
// }
// }