Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xy] Cache project settings to improve perf. #4581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mage_ai/settings/platform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from functools import lru_cache
from pathlib import Path
from typing import Dict

Expand Down Expand Up @@ -287,6 +288,7 @@ def active_project_settings(
)


@lru_cache(maxsize=20)
def project_platform_settings(repo_path: str = None, mage_projects_only: bool = False) -> Dict:
mapping = (__combined_platform_settings(
repo_path=repo_path,
Expand Down Expand Up @@ -317,6 +319,7 @@ def update_settings(settings: Dict) -> Dict:
content = yaml.dump(settings)

safe_write(platform_settings_full_path(), content)
project_platform_settings.cache_clear()


def __combined_platform_settings(repo_path: str = None, mage_projects_only: bool = False) -> Dict:
Expand Down Expand Up @@ -417,6 +420,7 @@ def local_platform_settings_full_path(repo_path: str = None) -> str:
return os.path.join(variables_dir, LOCAL_PLATFORM_SETTINGS_FILENAME)


@lru_cache(maxsize=20)
def __local_platform_settings(repo_path: str = None) -> Dict:
"""
Retrieve and return the local platform settings.
Expand Down Expand Up @@ -450,3 +454,5 @@ def __update_local_platform_settings(
full_path = local_platform_settings_full_path(repo_path=repo_path)
content = yaml.dump(platform_settings)
safe_write(full_path, content)

__local_platform_settings.cache_clear()
Loading