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