diff --git a/api/connection.go b/api/connection.go index c61913818..6312f76b6 100644 --- a/api/connection.go +++ b/api/connection.go @@ -7,7 +7,6 @@ import ( type ReadTransaction interface { GetObject(bucketName string, key []byte, object interface{}) error GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error - GetAllWithJsoniter(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, append func(o interface{}) (interface{}, error)) error } diff --git a/api/database/boltdb/db.go b/api/database/boltdb/db.go index 7d9d9786d..638e26d89 100644 --- a/api/database/boltdb/db.go +++ b/api/database/boltdb/db.go @@ -330,13 +330,6 @@ func (connection *DbConnection) GetAll(bucketName string, obj interface{}, appen }) } -// TODO: decide which Unmarshal to use, and use one... -func (connection *DbConnection) GetAllWithJsoniter(bucketName string, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error { - return connection.ViewTx(func(tx portainer.Transaction) error { - return tx.GetAllWithJsoniter(bucketName, obj, appendFn) - }) -} - func (connection *DbConnection) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error { return connection.ViewTx(func(tx portainer.Transaction) error { return tx.GetAllWithKeyPrefix(bucketName, keyPrefix, obj, appendFn) diff --git a/api/database/boltdb/tx.go b/api/database/boltdb/tx.go index 9aede519a..57cc40140 100644 --- a/api/database/boltdb/tx.go +++ b/api/database/boltdb/tx.go @@ -132,19 +132,6 @@ func (tx *DbTransaction) GetAll(bucketName string, obj interface{}, appendFn fun }) } -func (tx *DbTransaction) GetAllWithJsoniter(bucketName string, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error { - bucket := tx.tx.Bucket([]byte(bucketName)) - - return bucket.ForEach(func(k []byte, v []byte) error { - err := tx.conn.UnmarshalObject(v, obj) - if err == nil { - obj, err = appendFn(obj) - } - - return err - }) -} - func (tx *DbTransaction) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error { cursor := tx.tx.Bucket([]byte(bucketName)).Cursor() diff --git a/api/dataservices/base_tx.go b/api/dataservices/base_tx.go index bf273233b..db1e702cb 100644 --- a/api/dataservices/base_tx.go +++ b/api/dataservices/base_tx.go @@ -31,7 +31,7 @@ func (service BaseDataServiceTx[T, I]) Read(ID I) (*T, error) { func (service BaseDataServiceTx[T, I]) ReadAll() ([]T, error) { var collection = make([]T, 0) - return collection, service.Tx.GetAllWithJsoniter( + return collection, service.Tx.GetAll( service.Bucket, new(T), AppendFn(&collection), diff --git a/api/dataservices/endpoint/tx.go b/api/dataservices/endpoint/tx.go index 8c8e3c98b..bd6246c41 100644 --- a/api/dataservices/endpoint/tx.go +++ b/api/dataservices/endpoint/tx.go @@ -20,10 +20,10 @@ func (service ServiceTx) BucketName() string { // Endpoint returns an environment(endpoint) by ID. func (service ServiceTx) Endpoint(ID portainer.EndpointID) (*portainer.Endpoint, error) { var endpoint portainer.Endpoint + identifier := service.service.connection.ConvertToKey(int(ID)) - err := service.tx.GetObject(BucketName, identifier, &endpoint) - if err != nil { + if err := service.tx.GetObject(BucketName, identifier, &endpoint); err != nil { return nil, err } @@ -36,8 +36,7 @@ func (service ServiceTx) Endpoint(ID portainer.EndpointID) (*portainer.Endpoint, func (service ServiceTx) UpdateEndpoint(ID portainer.EndpointID, endpoint *portainer.Endpoint) error { identifier := service.service.connection.ConvertToKey(int(ID)) - err := service.tx.UpdateObject(BucketName, identifier, endpoint) - if err != nil { + if err := service.tx.UpdateObject(BucketName, identifier, endpoint); err != nil { return err } @@ -45,6 +44,7 @@ func (service ServiceTx) UpdateEndpoint(ID portainer.EndpointID, endpoint *porta if len(endpoint.EdgeID) > 0 { service.service.idxEdgeID[endpoint.EdgeID] = ID } + service.service.heartbeats.Store(ID, endpoint.LastCheckInDate) service.service.mu.Unlock() @@ -57,8 +57,7 @@ func (service ServiceTx) UpdateEndpoint(ID portainer.EndpointID, endpoint *porta func (service ServiceTx) DeleteEndpoint(ID portainer.EndpointID) error { identifier := service.service.connection.ConvertToKey(int(ID)) - err := service.tx.DeleteObject(BucketName, identifier) - if err != nil { + if err := service.tx.DeleteObject(BucketName, identifier); err != nil { return err } @@ -70,6 +69,7 @@ func (service ServiceTx) DeleteEndpoint(ID portainer.EndpointID) error { break } } + service.service.heartbeats.Delete(ID) service.service.mu.Unlock() @@ -82,7 +82,7 @@ func (service ServiceTx) DeleteEndpoint(ID portainer.EndpointID) error { func (service ServiceTx) Endpoints() ([]portainer.Endpoint, error) { var endpoints = make([]portainer.Endpoint, 0) - return endpoints, service.tx.GetAllWithJsoniter( + return endpoints, service.tx.GetAll( BucketName, &portainer.Endpoint{}, dataservices.AppendFn(&endpoints), @@ -107,8 +107,7 @@ func (service ServiceTx) UpdateHeartbeat(endpointID portainer.EndpointID) { // CreateEndpoint assign an ID to a new environment(endpoint) and saves it. func (service ServiceTx) Create(endpoint *portainer.Endpoint) error { - err := service.tx.CreateObjectWithId(BucketName, int(endpoint.ID), endpoint) - if err != nil { + if err := service.tx.CreateObjectWithId(BucketName, int(endpoint.ID), endpoint); err != nil { return err } @@ -116,6 +115,7 @@ func (service ServiceTx) Create(endpoint *portainer.Endpoint) error { if len(endpoint.EdgeID) > 0 { service.service.idxEdgeID[endpoint.EdgeID] = endpoint.ID } + service.service.heartbeats.Store(endpoint.ID, endpoint.LastCheckInDate) service.service.mu.Unlock() @@ -134,6 +134,7 @@ func (service ServiceTx) EndpointsByTeamID(teamID portainer.TeamID) ([]portainer return true } } + return false }), ) diff --git a/go.mod b/go.mod index 651d2dad9..4ba2acf11 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( github.com/docker/cli v26.0.1+incompatible github.com/docker/docker v26.0.1+incompatible github.com/fvbommel/sortorder v1.0.2 - github.com/fxamacker/cbor/v2 v2.4.0 github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814 github.com/go-git/go-git/v5 v5.11.0 github.com/go-ldap/ldap/v3 v3.4.1 @@ -149,7 +148,6 @@ require ( github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect github.com/ulikunitz/xz v0.5.11 // indirect github.com/vbatts/tar-split v0.11.5 // indirect - github.com/x448/float16 v0.8.4 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect diff --git a/go.sum b/go.sum index 9b70b4aaa..2b14907a3 100644 --- a/go.sum +++ b/go.sum @@ -122,8 +122,6 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4 github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fvbommel/sortorder v1.0.2 h1:mV4o8B2hKboCdkJm+a7uX/SIpZob4JzUpc5GGnM45eo= github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0= -github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= -github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814 h1:gWvniJ4GbFfkf700kykAImbLiEMU0Q3QN9hQ26Js1pU= github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814/go.mod h1:secRm32Ro77eD23BmPVbgLbWN+JWDw7pJszenjxI4bI= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= @@ -381,8 +379,6 @@ github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinC github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk= github.com/viney-shih/go-lock v1.1.1 h1:SwzDPPAiHpcwGCr5k8xD15d2gQSo8d4roRYd7TDV2eI= github.com/viney-shih/go-lock v1.1.1/go.mod h1:Yijm78Ljteb3kRiJrbLAxVntkUukGu5uzSxq/xV7OO8= -github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= -github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=