41 lines
949 B
Go
41 lines
949 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"91porn-server/common/elastic"
|
|
"91porn-server/common/log"
|
|
"91porn-server/models"
|
|
"91porn-server/models/v/fictionmod"
|
|
"91porn-server/skd/skdg"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
func syncFiction(wg *sync.WaitGroup) {
|
|
log.Info("fiction sync start...")
|
|
for i := int64(0); ; i++ {
|
|
opts := options.Find().SetSkip(i * 1000).SetLimit(1000).SetSort(bson.D{{Key: "_id", Value: 1}})
|
|
fc, err := fictionmod.GetListByCond(bson.M{}, opts)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var source = elastic.M{}
|
|
for i := range fc {
|
|
tmp := fc[i]
|
|
source[fc[i].ID.Hex()] = tmp
|
|
}
|
|
if err := skdg.VideoES.Bulk(models.ESInfoFictionTable, source); err != nil {
|
|
panic(err)
|
|
}
|
|
fcLen := len(fc)
|
|
if fcLen < 1000 {
|
|
break
|
|
}
|
|
log.Info("fiction sync:", log.Any("start", i*1000), log.Any("end", i*1000+int64(fcLen)))
|
|
}
|
|
log.Info("fiction sync complete...")
|
|
wg.Done()
|
|
}
|