Skip to content

Commit

Permalink
Merge pull request #3753 from opsmill/fac-some-perf-optim
Browse files Browse the repository at this point in the history
fix(backend): various perf optimizations
  • Loading branch information
fatih-acar authored Jul 8, 2024
2 parents 48e16d0 + 6cb7a00 commit 52c0cc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion backend/infrahub/core/schema/attribute_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class AttributeSchema(GeneratedAttributeSchema):
_sort_by: list[str] = ["name"]
_enum_class: Optional[type[enum.Enum]] = None

@property
def is_attribute(self) -> bool:
Expand Down Expand Up @@ -65,7 +66,9 @@ def get_branch(self) -> BranchSupportType:
def get_enum_class(self) -> type[enum.Enum]:
if not self.enum:
raise ValueError(f"{self.name} is not an Enum")
return generate_python_enum(name=f"{self.name.title()}Enum", options=self.enum)
if not self._enum_class:
self._enum_class = generate_python_enum(name=f"{self.name.title()}Enum", options=self.enum)
return self._enum_class

def convert_value_to_enum(self, value: Any) -> Optional[enum.Enum]:
if isinstance(value, enum.Enum) or value is None:
Expand Down
6 changes: 4 additions & 2 deletions python_sdk/infrahub_sdk/uuidt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
BASE = 16
DIVISOR = BASE - 1
CHARACTERS = list("0123456789abcdefghijklmnopqrstuvwxyz")[:BASE]
HOSTNAME = socket.gethostname()
DEFAULT_NAMESPACE = str(Path(__file__).parent.resolve())

# Code inspired from https://github.com/isaacharrisholt/uuidt

Expand Down Expand Up @@ -39,9 +41,9 @@ def __init__(
hostname: Optional[str] = None,
random_chars: Optional[str] = None,
):
self.namespace = namespace or str(Path(__file__).parent.resolve())
self.namespace = namespace or DEFAULT_NAMESPACE
self.timestamp = timestamp or time.time_ns()
self.hostname = hostname or socket.gethostname()
self.hostname = hostname or HOSTNAME
self.random_chars = random_chars or "".join(random.choices(CHARACTERS, k=8))

def __str__(self) -> str:
Expand Down

0 comments on commit 52c0cc5

Please sign in to comment.