mirror of https://gitee.com/answerdev/answer.git
fix post-title
This commit is contained in:
parent
3378cbff69
commit
3092954e68
|
@ -165,7 +165,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
answerCommon := answercommon.NewAnswerCommon(answerRepo)
|
||||
metaRepo := meta.NewMetaRepo(dataData)
|
||||
metaService := meta2.NewMetaService(metaRepo)
|
||||
questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaService, configService)
|
||||
questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaService, configService, dataData)
|
||||
collectionService := service.NewCollectionService(collectionRepo, collectionGroupRepo, questionCommon)
|
||||
collectionController := controller.NewCollectionController(collectionService)
|
||||
answerActivityRepo := activity.NewAnswerActivityRepo(dataData, activityRepo, userRankRepo)
|
||||
|
@ -193,7 +193,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
reasonService := reason2.NewReasonService(reasonRepo)
|
||||
reasonController := controller.NewReasonController(reasonService)
|
||||
themeController := controller_admin.NewThemeController()
|
||||
siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, siteInfoCommonService, emailService, tagCommonService, configService)
|
||||
siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, siteInfoCommonService, emailService, tagCommonService, configService, questionCommon)
|
||||
siteInfoController := controller_admin.NewSiteInfoController(siteInfoService)
|
||||
siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
|
||||
notificationRepo := notification.NewNotificationRepo(dataData)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/entity"
|
||||
collectioncommon "github.com/answerdev/answer/internal/service/collection_common"
|
||||
"github.com/answerdev/answer/internal/service/unique"
|
||||
"github.com/answerdev/answer/pkg/uid"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -148,6 +149,9 @@ func (cr *collectionRepo) GetCollectionPage(ctx context.Context, page, pageSize
|
|||
// SearchObjectCollected check object is collected or not
|
||||
func (cr *collectionRepo) SearchObjectCollected(ctx context.Context, userID string, objectIds []string) (map[string]bool, error) {
|
||||
collectedMap := make(map[string]bool)
|
||||
for k, object_id := range objectIds {
|
||||
objectIds[k] = uid.DeShortID(object_id)
|
||||
}
|
||||
list, err := cr.SearchByObjectIDsAndUser(ctx, userID, objectIds)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
|
|
@ -3,9 +3,12 @@ package questioncommon
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/base/data"
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/service/activity_common"
|
||||
|
@ -64,6 +67,7 @@ type QuestionCommon struct {
|
|||
AnswerCommon *answercommon.AnswerCommon
|
||||
metaService *meta.MetaService
|
||||
configService *config.ConfigService
|
||||
data *data.Data
|
||||
}
|
||||
|
||||
func NewQuestionCommon(questionRepo QuestionRepo,
|
||||
|
@ -76,6 +80,8 @@ func NewQuestionCommon(questionRepo QuestionRepo,
|
|||
answerCommon *answercommon.AnswerCommon,
|
||||
metaService *meta.MetaService,
|
||||
configService *config.ConfigService,
|
||||
data *data.Data,
|
||||
|
||||
) *QuestionCommon {
|
||||
return &QuestionCommon{
|
||||
questionRepo: questionRepo,
|
||||
|
@ -88,6 +94,7 @@ func NewQuestionCommon(questionRepo QuestionRepo,
|
|||
AnswerCommon: answerCommon,
|
||||
metaService: metaService,
|
||||
configService: configService,
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -543,6 +550,57 @@ func (as *QuestionCommon) RemoveAnswer(ctx context.Context, id string) (err erro
|
|||
return as.answerRepo.RemoveAnswer(ctx, id)
|
||||
}
|
||||
|
||||
func (qs *QuestionCommon) SitemapCron(ctx context.Context) {
|
||||
data := &schema.SiteMapList{}
|
||||
questionNum, err := qs.questionRepo.GetQuestionCount(ctx)
|
||||
if err != nil {
|
||||
log.Error("GetQuestionCount error", err)
|
||||
return
|
||||
}
|
||||
if questionNum <= schema.SitemapMaxSize {
|
||||
questionIDList, err := qs.questionRepo.GetQuestionIDsPage(ctx, 0, int(questionNum))
|
||||
if err != nil {
|
||||
log.Error("GetQuestionIDsPage error", err)
|
||||
return
|
||||
}
|
||||
data.QuestionIDs = questionIDList
|
||||
|
||||
} else {
|
||||
nums := make([]int, 0)
|
||||
totalpages := int(math.Ceil(float64(questionNum) / float64(schema.SitemapMaxSize)))
|
||||
for i := 1; i <= totalpages; i++ {
|
||||
siteMapPagedata := &schema.SiteMapPageList{}
|
||||
nums = append(nums, i)
|
||||
questionIDList, err := qs.questionRepo.GetQuestionIDsPage(ctx, i, int(schema.SitemapMaxSize))
|
||||
if err != nil {
|
||||
log.Error("GetQuestionIDsPage error", err)
|
||||
return
|
||||
}
|
||||
siteMapPagedata.PageData = questionIDList
|
||||
if setCacheErr := qs.SetCache(ctx, fmt.Sprintf(schema.SitemapPageCachekey, i), siteMapPagedata); setCacheErr != nil {
|
||||
log.Errorf("set sitemap cron SetCache failed: %s", setCacheErr)
|
||||
}
|
||||
}
|
||||
data.MaxPageNum = nums
|
||||
}
|
||||
if setCacheErr := qs.SetCache(ctx, schema.SitemapCachekey, data); setCacheErr != nil {
|
||||
log.Errorf("set sitemap cron SetCache failed: %s", setCacheErr)
|
||||
}
|
||||
}
|
||||
|
||||
func (qs *QuestionCommon) SetCache(ctx context.Context, cachekey string, info interface{}) error {
|
||||
infoStr, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||
}
|
||||
|
||||
err = qs.data.Cache.SetString(ctx, cachekey, string(infoStr), schema.DashBoardCacheTime)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qs *QuestionCommon) ShowListFormat(ctx context.Context, data *entity.Question) *schema.QuestionInfo {
|
||||
return qs.ShowFormat(ctx, data)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package service
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -1347,52 +1346,5 @@ func (qs *QuestionService) changeQuestionToRevision(ctx context.Context, questio
|
|||
}
|
||||
|
||||
func (qs *QuestionService) SitemapCron(ctx context.Context) {
|
||||
data := &schema.SiteMapList{}
|
||||
questionNum, err := qs.questionRepo.GetQuestionCount(ctx)
|
||||
if err != nil {
|
||||
log.Error("GetQuestionCount error", err)
|
||||
return
|
||||
}
|
||||
if questionNum <= schema.SitemapMaxSize {
|
||||
questionIDList, err := qs.questionRepo.GetQuestionIDsPage(ctx, 0, int(questionNum))
|
||||
if err != nil {
|
||||
log.Error("GetQuestionIDsPage error", err)
|
||||
return
|
||||
}
|
||||
data.QuestionIDs = questionIDList
|
||||
|
||||
} else {
|
||||
nums := make([]int, 0)
|
||||
totalpages := int(math.Ceil(float64(questionNum) / float64(schema.SitemapMaxSize)))
|
||||
for i := 1; i <= totalpages; i++ {
|
||||
siteMapPagedata := &schema.SiteMapPageList{}
|
||||
nums = append(nums, i)
|
||||
questionIDList, err := qs.questionRepo.GetQuestionIDsPage(ctx, i, int(schema.SitemapMaxSize))
|
||||
if err != nil {
|
||||
log.Error("GetQuestionIDsPage error", err)
|
||||
return
|
||||
}
|
||||
siteMapPagedata.PageData = questionIDList
|
||||
if setCacheErr := qs.SetCache(ctx, fmt.Sprintf(schema.SitemapPageCachekey, i), siteMapPagedata); setCacheErr != nil {
|
||||
log.Errorf("set sitemap cron SetCache failed: %s", setCacheErr)
|
||||
}
|
||||
}
|
||||
data.MaxPageNum = nums
|
||||
}
|
||||
if setCacheErr := qs.SetCache(ctx, schema.SitemapCachekey, data); setCacheErr != nil {
|
||||
log.Errorf("set sitemap cron SetCache failed: %s", setCacheErr)
|
||||
}
|
||||
}
|
||||
|
||||
func (qs *QuestionService) SetCache(ctx context.Context, cachekey string, info interface{}) error {
|
||||
infoStr, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||
}
|
||||
|
||||
err = qs.data.Cache.SetString(ctx, cachekey, string(infoStr), schema.DashBoardCacheTime)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||
}
|
||||
return nil
|
||||
qs.questioncommon.SitemapCron(ctx)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service/config"
|
||||
"github.com/answerdev/answer/internal/service/export"
|
||||
questioncommon "github.com/answerdev/answer/internal/service/question_common"
|
||||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||
"github.com/answerdev/answer/pkg/uid"
|
||||
|
@ -28,6 +29,7 @@ type SiteInfoService struct {
|
|||
emailService *export.EmailService
|
||||
tagCommonService *tagcommon.TagCommonService
|
||||
configService *config.ConfigService
|
||||
questioncommon *questioncommon.QuestionCommon
|
||||
}
|
||||
|
||||
func NewSiteInfoService(
|
||||
|
@ -36,6 +38,8 @@ func NewSiteInfoService(
|
|||
emailService *export.EmailService,
|
||||
tagCommonService *tagcommon.TagCommonService,
|
||||
configService *config.ConfigService,
|
||||
questioncommon *questioncommon.QuestionCommon,
|
||||
|
||||
) *SiteInfoService {
|
||||
plugin.RegisterGetSiteURLFunc(func() string {
|
||||
generalSiteInfo, err := siteInfoCommonService.GetSiteGeneral(context.Background())
|
||||
|
@ -52,6 +56,7 @@ func NewSiteInfoService(
|
|||
emailService: emailService,
|
||||
tagCommonService: tagCommonService,
|
||||
configService: configService,
|
||||
questioncommon: questioncommon,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,6 +300,7 @@ func (s *SiteInfoService) SaveSeo(ctx context.Context, req schema.SiteSeoReq) (e
|
|||
} else {
|
||||
uid.ShortIDSwitch = false
|
||||
}
|
||||
s.questioncommon.SitemapCron(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue