137 lines
3.8 KiB
Go
137 lines
3.8 KiB
Go
package sitemap
|
|
|
|
import (
|
|
"context"
|
|
"videoweb/pub/models/contenttagmod"
|
|
"videoweb/pub/models/playletcategorymod"
|
|
"videoweb/pub/models/playletmod"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
// getPlayletList 拉取已上架短剧,并收集实际用到的分类/标签 ID。
|
|
func getPlayletList(ctx context.Context) ([]idWithTime, map[int64]struct{}, map[int64]struct{}) {
|
|
filter := bson.M{
|
|
playletmod.FN.Playlet.Status: playletmod.StatusUp,
|
|
}
|
|
pageSize := int64(1000)
|
|
items := make([]idWithTime, 0)
|
|
categoryIDs := make(map[int64]struct{})
|
|
tagIDs := make(map[int64]struct{})
|
|
for i := int64(0); i < 500; i++ {
|
|
skip := i * pageSize
|
|
list, _ := playletmod.FindManyPlaylet(ctx, filter, options.Find().
|
|
SetSort(bson.M{playletmod.FN.Playlet.Id: -1}).
|
|
SetSkip(skip).
|
|
SetLimit(pageSize).
|
|
SetProjection(bson.M{
|
|
playletmod.FN.Playlet.Id: 1,
|
|
playletmod.FN.Playlet.Slug: 1,
|
|
playletmod.FN.Playlet.UpdatedAt: 1,
|
|
playletmod.FN.Playlet.OnlineAt: 1,
|
|
playletmod.FN.Playlet.CategoryIds: 1,
|
|
playletmod.FN.Playlet.TagIds: 1,
|
|
}))
|
|
for _, info := range list {
|
|
if info == nil || info.Id <= 0 {
|
|
continue
|
|
}
|
|
lastMod := info.UpdatedAt
|
|
if lastMod.IsZero() {
|
|
lastMod = info.OnlineAt
|
|
}
|
|
items = append(items, idWithTime{Id: info.Id, Slug: info.Slug, LastMod: lastMod})
|
|
for _, id := range info.CategoryIds {
|
|
if id > 0 {
|
|
categoryIDs[id] = struct{}{}
|
|
}
|
|
}
|
|
for _, id := range info.TagIds {
|
|
if id > 0 {
|
|
tagIDs[id] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
if len(list) < int(pageSize) {
|
|
break
|
|
}
|
|
}
|
|
return items, categoryIDs, tagIDs
|
|
}
|
|
|
|
// getPlayletCategoryList 只收录有上架短剧的分类,避免空列表页被抓取。
|
|
func getPlayletCategoryList(ctx context.Context, usedCategoryIDs map[int64]struct{}) []idWithTime {
|
|
if len(usedCategoryIDs) == 0 {
|
|
return nil
|
|
}
|
|
filter := bson.M{
|
|
playletcategorymod.FN.PlayletCategory.Status: true,
|
|
}
|
|
pageSize := int64(1000)
|
|
items := make([]idWithTime, 0)
|
|
for i := int64(0); i < 100; i++ {
|
|
skip := i * pageSize
|
|
list, _ := playletcategorymod.FindManyPlayletCategory(ctx, filter, options.Find().
|
|
SetSort(bson.M{playletcategorymod.FN.PlayletCategory.Rank: -1}).
|
|
SetSkip(skip).
|
|
SetLimit(pageSize).
|
|
SetProjection(bson.M{
|
|
playletcategorymod.FN.PlayletCategory.Id: 1,
|
|
playletcategorymod.FN.PlayletCategory.Slug: 1,
|
|
playletcategorymod.FN.PlayletCategory.UpdatedAt: 1,
|
|
}))
|
|
for _, info := range list {
|
|
if info == nil || info.Id <= 0 {
|
|
continue
|
|
}
|
|
if _, ok := usedCategoryIDs[info.Id]; !ok {
|
|
continue
|
|
}
|
|
items = append(items, idWithTime{Id: info.Id, Slug: info.Slug, LastMod: info.UpdatedAt})
|
|
}
|
|
if len(list) < int(pageSize) {
|
|
break
|
|
}
|
|
}
|
|
return items
|
|
}
|
|
|
|
// getContentTagList 只收录当前频道已绑定内容的统一标签。
|
|
func getContentTagList(ctx context.Context, usedTagIDs map[int64]struct{}, tagType contenttagmod.ContentTagType) []idWithTime {
|
|
if len(usedTagIDs) == 0 {
|
|
return nil
|
|
}
|
|
filter := bson.M{
|
|
contenttagmod.FN.ContentTag.Status: true,
|
|
contenttagmod.FN.ContentTag.Types: tagType,
|
|
}
|
|
pageSize := int64(1000)
|
|
items := make([]idWithTime, 0)
|
|
for i := int64(0); i < 100; i++ {
|
|
skip := i * pageSize
|
|
list, _ := contenttagmod.FindManyContentTag(ctx, filter, options.Find().
|
|
SetSort(bson.M{contenttagmod.FN.ContentTag.Rank: -1}).
|
|
SetSkip(skip).
|
|
SetLimit(pageSize).
|
|
SetProjection(bson.M{
|
|
contenttagmod.FN.ContentTag.Id: 1,
|
|
contenttagmod.FN.ContentTag.Slug: 1,
|
|
contenttagmod.FN.ContentTag.UpdatedAt: 1,
|
|
}))
|
|
for _, info := range list {
|
|
if info == nil || info.Id <= 0 {
|
|
continue
|
|
}
|
|
if _, ok := usedTagIDs[info.Id]; !ok {
|
|
continue
|
|
}
|
|
items = append(items, idWithTime{Id: info.Id, Slug: info.Slug, LastMod: info.UpdatedAt})
|
|
}
|
|
if len(list) < int(pageSize) {
|
|
break
|
|
}
|
|
}
|
|
return items
|
|
}
|