test
This commit is contained in:
parent
585cb289a9
commit
5ae46dca5f
26
obj.go
26
obj.go
@ -343,6 +343,11 @@ func addObjMsg(m ChatWarsMessage) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getObjMsg(objId int64) (*ChatWarsMessage, error) {
|
func getObjMsg(objId int64) (*ChatWarsMessage, error) {
|
||||||
|
var (
|
||||||
|
name string
|
||||||
|
data []byte
|
||||||
|
)
|
||||||
|
|
||||||
if v, ok := cacheObjMsg.Load(objId); ok {
|
if v, ok := cacheObjMsg.Load(objId); ok {
|
||||||
m := v.(ChatWarsMessage)
|
m := v.(ChatWarsMessage)
|
||||||
return &m, nil
|
return &m, nil
|
||||||
@ -357,6 +362,7 @@ func getObjMsg(objId int64) (*ChatWarsMessage, error) {
|
|||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
|
||||||
m = new(ChatWarsMessage)
|
m = new(ChatWarsMessage)
|
||||||
|
m.Callbacks = []ChatWarsCallback{}
|
||||||
|
|
||||||
err = stmt.QueryRow(objId).Scan(&m.ID64, &m.ChatID64, &m.TGUserID64, &m.TGSenderUserID64, &m.Date, &m.Text)
|
err = stmt.QueryRow(objId).Scan(&m.ID64, &m.ChatID64, &m.TGUserID64, &m.TGSenderUserID64, &m.Date, &m.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -365,6 +371,24 @@ func getObjMsg(objId int64) (*ChatWarsMessage, error) {
|
|||||||
|
|
||||||
m.ObjID64 = objId
|
m.ObjID64 = objId
|
||||||
|
|
||||||
|
stmt2, err := db.Prepare(`SELECT omc.name, omc.data FROM obj_msg_callback omv WHERE omc.obj_id = ?`)
|
||||||
|
if err != nil {
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
defer stmt2.Close()
|
||||||
|
|
||||||
|
rows, err := stmt2.Query(objId)
|
||||||
|
logOnError(err, "getObjMsg : Query callbacks")
|
||||||
|
for rows.Next() {
|
||||||
|
err = rows.Scan(&name, &data)
|
||||||
|
logOnError(err, "getObjMsg : scan next val")
|
||||||
|
cb := ChatWarsCallback{
|
||||||
|
Name: name,
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
m.Callbacks = append(m.Callbacks, cb)
|
||||||
|
}
|
||||||
|
|
||||||
cacheObjMsg.Store(objId, *m)
|
cacheObjMsg.Store(objId, *m)
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -814,7 +838,7 @@ func loadObjJob() error {
|
|||||||
cacheObjJob = make(map[int64]Job)
|
cacheObjJob = make(map[int64]Job)
|
||||||
muxObjJob.Unlock()
|
muxObjJob.Unlock()
|
||||||
|
|
||||||
jobs, err := db.Query(`SELECT o.id, o.obj_sub_type_id, oj.trigger_id, oj.timeout, oj.user_id, oj.zipped, oj.payload FROM obj o, obj_job oj WHERE o.id = oj.obj_id;;`)
|
jobs, err := db.Query(`SELECT o.id, o.obj_sub_type_id, oj.trigger_id, oj.timeout, oj.user_id, oj.zipped, oj.payload FROM obj o, obj_job oj WHERE o.id = oj.obj_id;`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
21
sql.go
21
sql.go
@ -541,6 +541,24 @@ func initDBViews() {
|
|||||||
failOnError(err, "initDBViews : create view obj_msg_vault_v")
|
failOnError(err, "initDBViews : create view obj_msg_vault_v")
|
||||||
log.Println("initDBViews : obj_msg_vault_v created ...")
|
log.Println("initDBViews : obj_msg_vault_v created ...")
|
||||||
|
|
||||||
|
_, err = db.Exec(`CREATE VIEW obj_msg_callback_v AS
|
||||||
|
SELECT om.obj_id
|
||||||
|
,o.obj_sub_type_id AS msg_type_id
|
||||||
|
,cost.intl_id COLLATE utf8mb4_unicode_ci AS msg_type
|
||||||
|
,om.msg_id
|
||||||
|
,om.chat_id
|
||||||
|
,omc.name COLLATE utf8mb4_unicode_ci AS name
|
||||||
|
,CAST(omc.data as CHAR) data
|
||||||
|
FROM obj_msg om
|
||||||
|
,obj o
|
||||||
|
,code_obj_sub_type cost
|
||||||
|
,obj_msg_callback omc
|
||||||
|
WHERE om.obj_id = o.id
|
||||||
|
AND cost.id = o.obj_sub_type_id
|
||||||
|
AND omc.obj_id = o.id;`)
|
||||||
|
failOnError(err, "initDBViews : create view obj_msg_callback_v")
|
||||||
|
log.Println("initDBViews : obj_msg_callback_v created ...")
|
||||||
|
|
||||||
log.Println("initDBViews : Views set up")
|
log.Println("initDBViews : Views set up")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,8 +756,7 @@ func getSQLListID64(q string) []int64 {
|
|||||||
)
|
)
|
||||||
|
|
||||||
rows, err := db.Query(q)
|
rows, err := db.Query(q)
|
||||||
s := fmt.Sprintf("getSQLListID64 : Query(%s)", q)
|
logOnError(err, "getSQLListID64 : "+q)
|
||||||
logOnError(err, s)
|
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err = rows.Scan(&id)
|
err = rows.Scan(&id)
|
||||||
|
Loading…
Reference in New Issue
Block a user