Skip to content

Commit 207ffc8

Browse files
committed
fix(backend): enable sdk schema cache only for task workers
Signed-off-by: Fatih Acar <[email protected]>
1 parent 9662b59 commit 207ffc8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

backend/infrahub/core/schema/manager.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from infrahub_sdk.schema import BranchSchema as SDKBranchSchema
66

77
from infrahub import lock
8+
from infrahub.components import ComponentType
89
from infrahub.core.manager import NodeManager
910
from infrahub.core.models import (
1011
HashableModelDiff,
@@ -26,6 +27,7 @@
2627
from infrahub.core.utils import parse_node_kind
2728
from infrahub.exceptions import SchemaNotFoundError
2829
from infrahub.log import get_logger
30+
from infrahub.workers.dependencies import get_component_type
2931

3032
from .constants import IGNORE_FOR_NODE
3133
from .schema_branch import SchemaBranch
@@ -42,7 +44,8 @@ class SchemaManager(NodeManager):
4244
def __init__(self) -> None:
4345
self._cache: dict[int, Any] = {}
4446
self._branches: dict[str, SchemaBranch] = {}
45-
self._sdk_branches: dict[str, SDKBranchSchema] = {}
47+
if get_component_type() == ComponentType.GIT_AGENT:
48+
self._sdk_branches: dict[str, SDKBranchSchema] = {}
4649

4750
def _get_from_cache(self, key: int) -> Any:
4851
return self._cache[key]
@@ -147,12 +150,16 @@ def get_schema_branch(self, name: str) -> SchemaBranch:
147150
return self._branches[name]
148151

149152
def get_sdk_schema_branch(self, name: str) -> SDKBranchSchema:
150-
return self._sdk_branches[name]
153+
if get_component_type() == ComponentType.GIT_AGENT:
154+
return self._sdk_branches[name]
155+
156+
raise Exception("get_sdk_schema_branch outside of task worker")
151157

152158
def set_schema_branch(self, name: str, schema: SchemaBranch) -> None:
153159
schema.name = name
154160
self._branches[name] = schema
155-
self._sdk_branches[name] = SDKBranchSchema.from_api_response(data=schema.to_dict_api_schema_object())
161+
if get_component_type() == ComponentType.GIT_AGENT:
162+
self._sdk_branches[name] = SDKBranchSchema.from_api_response(data=schema.to_dict_api_schema_object())
156163

157164
def process_schema_branch(self, name: str) -> None:
158165
schema_branch = self.get_schema_branch(name=name)
@@ -771,6 +778,8 @@ def purge_inactive_branches(self, active_branches: list[str]) -> list[str]:
771778
for branch_name in list(self._branches.keys()):
772779
if branch_name not in active_branches:
773780
del self._branches[branch_name]
781+
if get_component_type() == ComponentType.GIT_AGENT:
782+
del self._sdk_branches[branch_name]
774783
removed_branches.append(branch_name)
775784

776785
for hash_key in list(self._cache.keys()):

0 commit comments

Comments
 (0)