package svc import ( "errors" "net/rpc" "github.com/globalsign/mgo" "github.com/globalsign/mgo/bson" "mongo.games.com/goserver/core/logger" "mongo.games.com/game/common" "mongo.games.com/game/dbproxy/mongo" "mongo.games.com/game/model" ) var ( RankInviteDBName = "log" RankInviteCollName = "log_rankinvite" RankInviteColError = errors.New("RankInvite collection open failed") ) func RankInviteCollection(plt string) *mongo.Collection { s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, RankInviteDBName) if s != nil { c, first := s.DB().C(RankInviteCollName) if first { c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"num"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"-score"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"score"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"ts"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"week", "-score"}, Background: true, Sparse: true}) } return c } return nil } func SaveRankInvite(data *model.RankInvite) error { c := RankInviteCollection(data.Platform) if c == nil { return RankInviteColError } data.Week = common.GetWeekStartTs(data.Ts) _, err := c.Upsert(bson.M{"snid": data.SnId, "week": data.Week}, data) if err != nil { logger.Logger.Tracef("SaveRankInvite error:%v", err) return err } return nil } type RankInviteSvc struct { } func (svc *RankInviteSvc) SaveRankInvite(data *model.RankInvite, ret *bool) (err error) { err = SaveRankInvite(data) if err == nil { *ret = true } return } func init() { rpc.Register(new(RankInviteSvc)) }