update items cache

This commit is contained in:
shoopea 2020-01-12 20:03:30 +08:00
parent e1895ca172
commit ff29f889dc
2 changed files with 19 additions and 8 deletions

View File

@ -1,8 +1,6 @@
package main package main
import ( import ()
"log"
)
func reloadObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange bool, auction bool) { func reloadObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange bool, auction bool) {
var objID64 int64 var objID64 int64
@ -19,7 +17,7 @@ func reloadObjItem(code string, name string, itemTypeID64 int64, weight int64, e
c.ObjID64 = objID64 c.ObjID64 = objID64
c.ItemTypeID = itemTypeID64 c.ItemTypeID = itemTypeID64
c.Code = code c.Code = code
c.Name = name c.Name = append(c.Name, name)
c.Weight = weight c.Weight = weight
c.Exchange = exchange c.Exchange = exchange
c.Auction = auction c.Auction = auction

21
obj.go
View File

@ -749,7 +749,7 @@ func addObjQuest(userID64 int64, questTypeID64 int64, duration time.Duration, da
return objId, nil return objId, nil
} }
func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange bool, auction bool) (int64, error) { func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange string, auction bool) (int64, error) {
muxObjItem.Lock() muxObjItem.Lock()
defer muxObjItem.Unlock() defer muxObjItem.Unlock()
@ -762,7 +762,9 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exch
if err != nil { if err != nil {
return 0, nil return 0, nil
} else { } else {
obj.Names = append(obj.Names, name)
cacheObjItem[name] = obj cacheObjItem[name] = obj
cacheObjItem[code] = obj
return obj.ObjID64, nil return obj.ObjID64, nil
} }
@ -802,7 +804,7 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exch
defer stmt.Close() defer stmt.Close()
var e, a int var e, a int
if exchange { if exchange != `` {
e = 1 e = 1
} else { } else {
e = 0 e = 0
@ -834,7 +836,9 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exch
c.ObjID64 = objId c.ObjID64 = objId
c.ItemTypeID = itemTypeID64 c.ItemTypeID = itemTypeID64
c.Code = code c.Code = code
c.Name = name n := new([]string)
n = append(n, name)
c.Names = n
c.Weight = weight c.Weight = weight
c.Exchange = exchange c.Exchange = exchange
c.Auction = auction c.Auction = auction
@ -959,8 +963,17 @@ func loadObjItem2() error {
err = json.Unmarshal(b, &items) err = json.Unmarshal(b, &items)
for _, i := range items { for _, i := range items {
id := 0
for _, n := range i.Names { for _, n := range i.Names {
reloadObjItem(i.Code, n, i.ItemTypeID, i.Weight, (i.Exchange != nil), i.Auction) if id == 0 {
id = getSilentObjItemID(i.Code, ``)
if id == 0 {
id, err = addObjItem(i.Code, n, i.ItemTypeID, i.Weight, (i.Exchange != ``), i.Auction)
logOnError(err, "loadObjItem2 : addObjItem")
}
} else {
objAddName(id, n)
}
} }
} }
log.Printf("%d items loaded.\n", len(items)) log.Printf("%d items loaded.\n", len(items))