数据优化
This commit is contained in:
parent
fcf7922c42
commit
658eaa60d4
@ -4,6 +4,7 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -133,11 +134,12 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
conn_, err := db.Cross()
|
||||
dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn_)
|
||||
dbModel.AddList(uid, newData.Id, newData)
|
||||
this.module.SetPagodaRankList("pagodaList"+strconv.Itoa(int(newData.PagodaId)), newData.CostTime, newData.Id)
|
||||
this.module.SetPagodaRankList("pagodaList"+strconv.Itoa(int(newData.PagodaId)), int64(math.MaxInt32-newData.CostTime), newData.Id)
|
||||
dbModelTable := db.NewDBModel(comm.TableSeasonPagoda, time.Hour, conn_)
|
||||
if err = dbModelTable.Get(session.GetUserId(), pagoda); err == nil {
|
||||
dbModelTable.Change(session.GetUserId(), mapData) // 修改跨服数据
|
||||
this.module.SetPagodaRankList("pagodaSeasonRank", pagoda.PagodaId<<8+costTime, session.GetUserId())
|
||||
score := int64(pagoda.PagodaId)<<31 + int64(math.MaxInt32-costTime)
|
||||
this.module.SetPagodaRankList("pagodaSeasonRank", score, session.GetUserId())
|
||||
}
|
||||
}
|
||||
code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData)
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@ -35,7 +34,7 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.PagodaRankListR
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
)
|
||||
if req.FloorId == 0 {
|
||||
rd = pipe.ZRange("pagodaSeasonRank", 0, comm.MaxRankList)
|
||||
rd = pipe.ZRevRange("pagodaSeasonRank", 0, comm.MaxRankList)
|
||||
} else {
|
||||
rd = pipe.ZRange("pagodaList"+strconv.Itoa(int(req.FloorId)), 0, comm.MaxRankList)
|
||||
}
|
||||
@ -44,10 +43,11 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.PagodaRankListR
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
_data3 := rd.Val()
|
||||
for _, v := range _data3 {
|
||||
conn_, err := db.Cross()
|
||||
dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn_)
|
||||
_dataList := rd.Val()
|
||||
for _, v := range _dataList {
|
||||
//conn_, err := db.Cross()
|
||||
|
||||
dbModel := db.NewDBModel(comm.TableSeasonRecord, 0, conn)
|
||||
result := &pb.DBPagodaRecord{}
|
||||
if err = dbModel.GetListObj(session.GetUserId(), v, result); err == nil {
|
||||
szRank = append(szRank, result)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
//"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
@ -116,35 +117,37 @@ func (this *ModelRank) seasonSettlement() {
|
||||
Items []*pb.UserAssets
|
||||
)
|
||||
|
||||
rd := pipe.ZRange("pagodaSeasonRank", 0, comm.MaxRankList)
|
||||
rd := pipe.ZRevRange("pagodaSeasonRank", 0, comm.MaxRankList)
|
||||
_dataList := rd.Val()
|
||||
model1 := db.NewDBModel(comm.TableSeasonPagoda, time.Hour, conn)
|
||||
for index, v := range _dataList {
|
||||
result := &pb.DBPagodaRecord{}
|
||||
//result := &pb.DBVikingRank{}
|
||||
if err := model1.Get(v, result); err == nil {
|
||||
|
||||
if _, err = pipe.Exec(); err != nil {
|
||||
this.modulePagoda.Errorln(err)
|
||||
return
|
||||
}
|
||||
uids := rd.Val()
|
||||
|
||||
for index, uid := range uids {
|
||||
Items = make([]*pb.UserAssets, 0) //TO 排名配置
|
||||
for _, v := range rankReward {
|
||||
if len(v.Ranking) != 2 {
|
||||
continue
|
||||
}
|
||||
if index >= int(v.Ranking[0]) && index <= int(v.Ranking[1]) {
|
||||
for _, v1 := range v.Reward {
|
||||
Items = append(Items, &pb.UserAssets{
|
||||
A: v1.A,
|
||||
T: v1.T,
|
||||
N: v1.N,
|
||||
})
|
||||
if userinfo := this.modulePagoda.ModuleUser.GetUser(result.Uid); userinfo != nil {
|
||||
Items = make([]*pb.UserAssets, 0) //TO 排名配置
|
||||
for _, v := range rankReward {
|
||||
if len(v.Ranking) != 2 {
|
||||
continue
|
||||
}
|
||||
if index >= int(v.Ranking[0]) && index <= int(v.Ranking[1]) {
|
||||
for _, v1 := range v.Reward {
|
||||
Items = append(Items, &pb.UserAssets{
|
||||
A: v1.A,
|
||||
T: v1.T,
|
||||
N: v1.N,
|
||||
})
|
||||
}
|
||||
this.modulePagoda.mail.SendNewMail(&pb.DBMailData{
|
||||
CreateTime: uint64(configure.Now().Unix()),
|
||||
Items: Items,
|
||||
Cid: "SeasonPagodaReward",
|
||||
Param: []string{strconv.Itoa(index + 1)}, // 名次
|
||||
}, result.Uid)
|
||||
break
|
||||
}
|
||||
}
|
||||
this.modulePagoda.mail.SendNewMail(&pb.DBMailData{
|
||||
CreateTime: uint64(configure.Now().Unix()),
|
||||
Items: Items,
|
||||
Cid: "SeasonPagodaReward",
|
||||
Param: []string{strconv.Itoa(index)}, // 名次
|
||||
}, uid)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ func (this *Pagoda) CleanSeasonPagodaData() (code pb.ErrorCode) {
|
||||
}
|
||||
|
||||
// redis 排序 tableName:"pagodaList"
|
||||
func (this *Pagoda) SetPagodaRankList(tableName string, score int32, uid string) {
|
||||
func (this *Pagoda) SetPagodaRankList(tableName string, score int64, uid string) {
|
||||
if !this.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
var (
|
||||
|
@ -66,11 +66,11 @@ func (this *SeasonPagoda) Start() (err error) {
|
||||
if db.IsCross() {
|
||||
return
|
||||
}
|
||||
//time.Sleep(time.Second * 1)
|
||||
time.Sleep(time.Second * 1)
|
||||
//this.DbTest()
|
||||
conn, err := db.Cross()
|
||||
if err == nil {
|
||||
|
||||
this.DbTest()
|
||||
model := db.NewDBModel(comm.TableServerData, 0, conn)
|
||||
|
||||
_len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{})
|
||||
@ -196,7 +196,7 @@ func (this *SeasonPagoda) TimerSeasonStar() {
|
||||
}
|
||||
|
||||
func (this *SeasonPagoda) DbTest() {
|
||||
conn, err := db.Cross()
|
||||
conn, _ := db.Cross()
|
||||
model1 := db.NewDBModel(comm.TableVikingRank, time.Hour, conn)
|
||||
model1.Redis.Delete("vikingRank2")
|
||||
_d, err := model1.Redis.Keys("vikingrank:*")
|
||||
@ -206,8 +206,8 @@ func (this *SeasonPagoda) DbTest() {
|
||||
}
|
||||
fmt.Printf("%v", _d)
|
||||
}
|
||||
star := configure.Now()
|
||||
for i := 1; i < 10000; i++ {
|
||||
//star := configure.Now()
|
||||
for i := 1; i < 10; i++ {
|
||||
|
||||
new := &pb.DBVikingRank{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
@ -221,7 +221,8 @@ func (this *SeasonPagoda) DbTest() {
|
||||
Line: make([]*pb.LineUp, 5),
|
||||
CostTime: 12000 + int32(i),
|
||||
}
|
||||
model1.AddList(new.Uid, new.Id, new)
|
||||
//model1.AddList(new.Uid, new.Id, new)
|
||||
model1.Add(new.Uid, new)
|
||||
var (
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
menbers *redis.Z
|
||||
@ -231,7 +232,7 @@ func (this *SeasonPagoda) DbTest() {
|
||||
score = int64(i)<<31 + int64(math.MaxInt32-new.CostTime)
|
||||
tableName = "vikingRank" + strconv.Itoa(int(new.Bosstype))
|
||||
//vikingrank:mmmxxx1-63bbb137b96efbd321222ce7
|
||||
strKey := "vikingrank:" + new.Uid + "-" + new.Id // 自定义key
|
||||
strKey := new.Uid //"vikingrank:" + new.Uid + "-" + new.Id // 自定义key
|
||||
menbers = &redis.Z{Score: float64(score), Member: strKey}
|
||||
|
||||
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
||||
@ -243,10 +244,9 @@ func (this *SeasonPagoda) DbTest() {
|
||||
}
|
||||
if _, err := pipe.Exec(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
|
||||
}
|
||||
}
|
||||
this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
||||
//this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
||||
if true {
|
||||
var (
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
@ -262,11 +262,17 @@ func (this *SeasonPagoda) DbTest() {
|
||||
_dataList := rd.Val()
|
||||
for _, v := range _dataList {
|
||||
result := &pb.DBVikingRank{}
|
||||
|
||||
if err := model1.Redis.HGetAll(v, result); err == nil {
|
||||
if err := model1.Get(v, result); err == nil {
|
||||
//for _, v2 := range result {
|
||||
szRank = append(szRank, result)
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
// result := make([]*pb.DBVikingRank, 0)
|
||||
// if err := model1.GetList(v, &result); err == nil {
|
||||
// for _, v2 := range result {
|
||||
// szRank = append(szRank, v2)
|
||||
// }
|
||||
}
|
||||
this.module.Debugf("%v", szRank)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
@ -28,10 +29,10 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.VikingRankListR
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
|
||||
conn, _ := db.Local()
|
||||
if !req.Friend {
|
||||
var (
|
||||
pipe *pipe.RedisPipe = this.module.modelViking.Redis.RedisPipe(context.TODO())
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
)
|
||||
rd = pipe.ZRange("vikingRank"+strconv.Itoa(int(req.BoosType)), 0, -1)
|
||||
|
||||
@ -41,9 +42,13 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.VikingRankListR
|
||||
}
|
||||
_dataList := rd.Val()
|
||||
for _, v := range _dataList {
|
||||
result := &pb.DBVikingRank{}
|
||||
if err := this.module.modulerank.GetListObj(session.GetUserId(), v, result); err == nil {
|
||||
szRank = append(szRank, result)
|
||||
result := make([]*pb.DBVikingRank, 0)
|
||||
if err := this.module.modulerank.GetList(v, &result); err == nil {
|
||||
for _, v2 := range result {
|
||||
if v2.Bosstype == req.BoosType {
|
||||
szRank = append(szRank, v2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, report
|
||||
tableName string
|
||||
score int64
|
||||
)
|
||||
score = int64(difficulty<<31) + int64(math.MaxInt32-costTime)
|
||||
score = int64(difficulty)<<31 + int64(math.MaxInt32-costTime)
|
||||
tableName = "vikingRank" + strconv.Itoa(int(boosID))
|
||||
menbers = &redis.Z{Score: float64(score), Member: objID}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user