fix(performance): optimize performance for edge EE-3311 (#8040)
This commit is contained in:
26
api/internal/edge/cache/cache.go
vendored
Normal file
26
api/internal/edge/cache/cache.go
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
)
|
||||
|
||||
var c = fastcache.New(1)
|
||||
|
||||
func key(k portainer.EndpointID) []byte {
|
||||
return []byte(strconv.Itoa(int(k)))
|
||||
}
|
||||
|
||||
func Set(k portainer.EndpointID, v []byte) {
|
||||
c.Set(key(k), v)
|
||||
}
|
||||
|
||||
func Get(k portainer.EndpointID) ([]byte, bool) {
|
||||
return c.HasGet(nil, key(k))
|
||||
}
|
||||
|
||||
func Del(k portainer.EndpointID) {
|
||||
c.Del(key(k))
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package testhelpers
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
@@ -228,6 +229,34 @@ func (s *stubEndpointService) Endpoint(ID portainer.EndpointID) (*portainer.Endp
|
||||
return nil, errors.ErrObjectNotFound
|
||||
}
|
||||
|
||||
func (s *stubEndpointService) EndpointIDByEdgeID(edgeID string) (portainer.EndpointID, bool) {
|
||||
for _, endpoint := range s.endpoints {
|
||||
if endpoint.EdgeID == edgeID {
|
||||
return endpoint.ID, true
|
||||
}
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (s *stubEndpointService) Heartbeat(endpointID portainer.EndpointID) (int64, bool) {
|
||||
for i, endpoint := range s.endpoints {
|
||||
if endpoint.ID == endpointID {
|
||||
return s.endpoints[i].LastCheckInDate, true
|
||||
}
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (s *stubEndpointService) UpdateHeartbeat(endpointID portainer.EndpointID) {
|
||||
for i, endpoint := range s.endpoints {
|
||||
if endpoint.ID == endpointID {
|
||||
s.endpoints[i].LastCheckInDate = time.Now().Unix()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *stubEndpointService) Endpoints() ([]portainer.Endpoint, error) {
|
||||
return s.endpoints, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user