improve websocket ping and remodel for rename datapoint
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"maps"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/tecamino/tecamino-dbm/utils"
|
||||
ws "github.com/tecamino/tecamino-dbm/websocket"
|
||||
@@ -16,7 +14,7 @@ import (
|
||||
|
||||
type DBM struct {
|
||||
Datapoints Datapoint
|
||||
Uuids Uuids
|
||||
Uuids *Uuids
|
||||
Conns *ws.ClientHandler
|
||||
Log *logging.Logger
|
||||
}
|
||||
@@ -25,7 +23,7 @@ var SystemDatapoints uuid.UUID
|
||||
|
||||
func NewDBM(conns *ws.ClientHandler, log *logging.Logger) *DBM {
|
||||
return &DBM{
|
||||
Uuids: make(Uuids),
|
||||
Uuids: &Uuids{},
|
||||
Conns: conns,
|
||||
Log: log,
|
||||
}
|
||||
@@ -36,11 +34,7 @@ func (d *DBM) CreateDatapoints(sets ...json_dataModels.Set) ([]json_dataModels.S
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
dps, uuids, err := d.Datapoints.CreateDatapoints(sets...)
|
||||
|
||||
//save uuid in seperate map for fast look up
|
||||
maps.Copy(d.Uuids, uuids)
|
||||
|
||||
dps, err := d.Datapoints.CreateDatapoints(d.Uuids, sets...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -58,11 +52,10 @@ func (d *DBM) CreateDatapoints(sets ...json_dataModels.Set) ([]json_dataModels.S
|
||||
|
||||
func (d *DBM) ImportDatapoints(dps ...*Datapoint) error {
|
||||
for _, dp := range dps {
|
||||
uuids, err := d.Datapoints.ImportDatapoint(dp, dp.Path)
|
||||
err := d.Datapoints.ImportDatapoint(d.Uuids, dp, dp.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
maps.Copy(d.Uuids, uuids)
|
||||
|
||||
d.ModifyCountedDatapoints(1, false)
|
||||
}
|
||||
@@ -71,10 +64,10 @@ func (d *DBM) ImportDatapoints(dps ...*Datapoint) error {
|
||||
|
||||
func (d *DBM) UpdateDatapointValue(value any, uid uuid.UUID, path ...string) error {
|
||||
if uid != uuid.Nil {
|
||||
if _, ok := d.Uuids[uid]; !ok {
|
||||
dp := d.Uuids.GetDatapoint(uid)
|
||||
if dp == nil {
|
||||
return fmt.Errorf("uuid %s not found", uid.String())
|
||||
}
|
||||
dp := d.Uuids[uid]
|
||||
dp.Value = dp.Type.ConvertValue(value)
|
||||
dp.UpdateDateTime = time.Now().UnixMilli()
|
||||
dp.Publish(OnChange)
|
||||
@@ -90,11 +83,12 @@ func (d *DBM) UpdateDatapointValue(value any, uid uuid.UUID, path ...string) err
|
||||
func (d *DBM) RemoveDatapoint(sets ...json_dataModels.Set) (lsRemoved []json_dataModels.Set, err error) {
|
||||
for _, set := range sets {
|
||||
if set.Path == "" {
|
||||
if dp, ok := d.Uuids[set.Uuid]; ok {
|
||||
if dp := d.Uuids.GetDatapoint(set.Uuid); dp != nil {
|
||||
set.Path = dp.Path
|
||||
}
|
||||
}
|
||||
lsRemoved, err = d.Datapoints.RemoveDatapoint(d.Conns, set)
|
||||
|
||||
lsRemoved, err = d.Datapoints.RemoveDatapoint(set)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -105,11 +99,10 @@ func (d *DBM) RemoveDatapoint(sets ...json_dataModels.Set) (lsRemoved []json_dat
|
||||
|
||||
func (d *DBM) QueryDatapoints(depth uint, uid uuid.UUID, key ...string) []*Datapoint {
|
||||
if uid != uuid.Nil {
|
||||
if _, ok := d.Uuids[uid]; !ok {
|
||||
dp := d.Uuids.GetDatapoint(uid)
|
||||
if dp == nil {
|
||||
return nil
|
||||
}
|
||||
dp := d.Uuids[uid]
|
||||
if depth == 1 {
|
||||
} else if depth == 1 {
|
||||
return []*Datapoint{dp}
|
||||
}
|
||||
return append([]*Datapoint{}, dp.QueryDatapoints(depth, key[0])...)
|
||||
|
Reference in New Issue
Block a user