From 7df8196abafa31ca0f35a30687e4c057deadc763 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Wed, 27 Nov 2024 12:28:08 +0400 Subject: [PATCH 1/6] initiliase acl cache --- logic/acls.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/logic/acls.go b/logic/acls.go index 8863ce86d..6a99fb36c 100644 --- a/logic/acls.go +++ b/logic/acls.go @@ -18,6 +18,11 @@ var ( aclCacheMap = make(map[string]models.Acl) ) +func init() { + // load acls into cache + _ = listAcls() +} + // CreateDefaultAclNetworkPolicies - create default acl network policies func CreateDefaultAclNetworkPolicies(netID models.NetworkID) { if netID.String() == "" { From 698032a4dc78e26eb1399d8e062940fa058cfafb Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Wed, 27 Nov 2024 12:57:48 +0400 Subject: [PATCH 2/6] load acls into cache --- logic/acls.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/logic/acls.go b/logic/acls.go index 6a99fb36c..4cc887833 100644 --- a/logic/acls.go +++ b/logic/acls.go @@ -18,11 +18,6 @@ var ( aclCacheMap = make(map[string]models.Acl) ) -func init() { - // load acls into cache - _ = listAcls() -} - // CreateDefaultAclNetworkPolicies - create default acl network policies func CreateDefaultAclNetworkPolicies(netID models.NetworkID) { if netID.String() == "" { @@ -177,6 +172,9 @@ func InsertAcl(a models.Acl) error { func GetAcl(aID string) (models.Acl, error) { a := models.Acl{} if servercfg.CacheEnabled() { + if len(aclCacheMap) == 0 { + _ = listAcls() + } var ok bool a, ok = getAclFromCache(aID) if ok { From cde56204fcfa3703e14048838432e96f9e6d1f8e Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Wed, 27 Nov 2024 14:48:57 +0400 Subject: [PATCH 3/6] load all nodes into cache --- logic/nodes.go | 3 +++ netclient/ncutils/netclientutils.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/logic/nodes.go b/logic/nodes.go index 34eebe2e4..94e7199d5 100644 --- a/logic/nodes.go +++ b/logic/nodes.go @@ -445,6 +445,9 @@ func GetRecordKey(id string, network string) (string, error) { func GetNodeByID(uuid string) (models.Node, error) { if servercfg.CacheEnabled() { + if len(getNodesFromCache()) == 0 { + _, _ = GetAllNodes() + } if node, ok := getNodeFromCache(uuid); ok { return node, nil } diff --git a/netclient/ncutils/netclientutils.go b/netclient/ncutils/netclientutils.go index 9f79892d0..23fa9916d 100644 --- a/netclient/ncutils/netclientutils.go +++ b/netclient/ncutils/netclientutils.go @@ -6,7 +6,7 @@ import ( ) // DEFAULT_GC_PERCENT - garbage collection percent -const DEFAULT_GC_PERCENT = 10 +const DEFAULT_GC_PERCENT = 100 // == OS PATH FUNCTIONS == From cbe660fbf2134a20c22e1be0a3329755160bc29f Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Wed, 27 Nov 2024 15:01:26 +0400 Subject: [PATCH 4/6] get all nodes on startup --- logic/nodes.go | 3 --- migrate/migrate.go | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/logic/nodes.go b/logic/nodes.go index 94e7199d5..34eebe2e4 100644 --- a/logic/nodes.go +++ b/logic/nodes.go @@ -445,9 +445,6 @@ func GetRecordKey(id string, network string) (string, error) { func GetNodeByID(uuid string) (models.Node, error) { if servercfg.CacheEnabled() { - if len(getNodesFromCache()) == 0 { - _, _ = GetAllNodes() - } if node, ok := getNodeFromCache(uuid); ok { return node, nil } diff --git a/migrate/migrate.go b/migrate/migrate.go index 19e9232aa..e86f41999 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -20,6 +20,7 @@ import ( // Run - runs all migrations func Run() { + _, _ = logic.GetAllNodes() updateEnrollmentKeys() assignSuperAdmin() createDefaultTagsAndPolicies() From 64f730f6f0242a8740533daff4c8cd18314fbbb2 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Wed, 27 Nov 2024 15:05:08 +0400 Subject: [PATCH 5/6] list cache --- logic/acls.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/logic/acls.go b/logic/acls.go index 4cc887833..9a4dcb4aa 100644 --- a/logic/acls.go +++ b/logic/acls.go @@ -23,6 +23,7 @@ func CreateDefaultAclNetworkPolicies(netID models.NetworkID) { if netID.String() == "" { return } + _, _ = ListAcls(netID) if !IsAclExists(fmt.Sprintf("%s.%s", netID, "all-nodes")) { defaultDeviceAcl := models.Acl{ ID: fmt.Sprintf("%s.%s", netID, "all-nodes"), @@ -172,9 +173,6 @@ func InsertAcl(a models.Acl) error { func GetAcl(aID string) (models.Acl, error) { a := models.Acl{} if servercfg.CacheEnabled() { - if len(aclCacheMap) == 0 { - _ = listAcls() - } var ok bool a, ok = getAclFromCache(aID) if ok { From df7a1fae656b90a737e1a8ab6064b890fb77c854 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Wed, 27 Nov 2024 15:30:20 +0400 Subject: [PATCH 6/6] sync hosts into cache --- migrate/migrate.go | 1 + 1 file changed, 1 insertion(+) diff --git a/migrate/migrate.go b/migrate/migrate.go index e86f41999..b4a866ab7 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -21,6 +21,7 @@ import ( // Run - runs all migrations func Run() { _, _ = logic.GetAllNodes() + _, _ = logic.GetAllHosts() updateEnrollmentKeys() assignSuperAdmin() createDefaultTagsAndPolicies()