This commit is contained in:
shoopea 2020-01-12 22:04:50 +08:00
parent dca2f3e8df
commit 3bf7a9d555

77
obj.go
View File

@ -1054,83 +1054,6 @@ func loadObjItem2() error {
} }
func loadObjItem() error {
var (
id int64
type_id int64
intl_id string
name string
weight int64
)
muxObjItem.Lock()
cacheObjItem = make(map[string]ChatWarsItem)
muxObjItem.Unlock()
muxObjItemId.Lock()
cacheObjItemId = make(map[int64]ChatWarsItem)
muxObjItemId.Unlock()
items, err := db.Query(`SELECT oi.obj_id, o.obj_sub_type_id, oi.intl_id, obn.name, oi.weight FROM obj o, obj_item oi, obj_name obn WHERE o.id = oi.obj_id AND obn.obj_id = oi.obj_id AND obn.priority = 0;`)
if err != nil {
return err
}
defer items.Close()
for items.Next() {
err = items.Scan(&id, &type_id, &intl_id, &name, &weight)
if err != nil {
return err
}
c := new(ChatWarsItem)
c.ObjID64 = id
c.ItemTypeID = type_id
c.Code = intl_id
n := make([]string, 0)
n = append(n, name)
c.Names = n
c.Weight = weight
muxObjItem.Lock()
cacheObjItem[intl_id] = *c
cacheObjItem[name] = *c
muxObjItem.Unlock()
muxObjItemId.Lock()
cacheObjItemId[id] = *c
muxObjItemId.Unlock()
}
items2, err := db.Query(`SELECT oi.obj_id, oi.intl_id, obn.name, oi.weight FROM obj_item oi, obj_name obn WHERE obn.obj_id = oi.obj_id AND obn.priority > 0;`)
if err != nil {
return err
}
defer items2.Close()
for items2.Next() {
err = items2.Scan(&id, &intl_id, &name, &weight)
if err != nil {
return err
}
if c, ok := cacheObjItem[intl_id]; ok {
n := c.Names
n = append(n, name)
c.Names = n
muxObjItem.Lock()
cacheObjItem[intl_id] = c
for _, n := range c.Names {
cacheObjItem[n] = c
}
muxObjItem.Unlock()
} else {
log.Printf("loadObjItem : orphaned obj_name for `%s` : %s.\n", intl_id, name)
}
}
return nil
}
func loadObjJob() error { func loadObjJob() error {
var ( var (
id int64 id int64