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
import (
"log"
)
import ()
func reloadObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange bool, auction bool) {
var objID64 int64
@ -19,7 +17,7 @@ func reloadObjItem(code string, name string, itemTypeID64 int64, weight int64, e
c.ObjID64 = objID64
c.ItemTypeID = itemTypeID64
c.Code = code
c.Name = name
c.Name = append(c.Name, name)
c.Weight = weight
c.Exchange = exchange
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
}
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()
defer muxObjItem.Unlock()
@ -762,7 +762,9 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exch
if err != nil {
return 0, nil
} else {
obj.Names = append(obj.Names, name)
cacheObjItem[name] = obj
cacheObjItem[code] = obj
return obj.ObjID64, nil
}
@ -802,7 +804,7 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exch
defer stmt.Close()
var e, a int
if exchange {
if exchange != `` {
e = 1
} else {
e = 0
@ -834,7 +836,9 @@ func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exch
c.ObjID64 = objId
c.ItemTypeID = itemTypeID64
c.Code = code
c.Name = name
n := new([]string)
n = append(n, name)
c.Names = n
c.Weight = weight
c.Exchange = exchange
c.Auction = auction
@ -959,8 +963,17 @@ func loadObjItem2() error {
err = json.Unmarshal(b, &items)
for _, i := range items {
id := 0
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))