Skip to content

Commit

Permalink
Merge pull request #1088 from BigRoy/enhancement/collect_managed_stag…
Browse files Browse the repository at this point in the history
…ing_dir_avoid_db_queries

Avoid database queries when collecting managed staging dir
  • Loading branch information
BigRoy authored Jan 21, 2025
2 parents 44dcd68 + 41045c1 commit 1041fc7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/ayon_core/pipeline/publish/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ def get_instance_staging_dir(instance):
project_settings=context.data["project_settings"],
template_data=template_data,
always_return_path=True,
username=context.data["user"],
)

staging_dir_path = staging_dir_info.directory
Expand Down
6 changes: 5 additions & 1 deletion client/ayon_core/pipeline/staging_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def get_staging_dir_info(
logger: Optional[logging.Logger] = None,
prefix: Optional[str] = None,
suffix: Optional[str] = None,
username: Optional[str] = None,
) -> Optional[StagingDir]:
"""Get staging dir info data.
Expand Down Expand Up @@ -157,6 +158,7 @@ def get_staging_dir_info(
logger (Optional[logging.Logger]): Logger instance.
prefix (Optional[str]) Optional prefix for staging dir name.
suffix (Optional[str]): Optional suffix for staging dir name.
username (Optional[str]): AYON Username.
Returns:
Optional[StagingDir]: Staging dir info data
Expand All @@ -183,7 +185,9 @@ def get_staging_dir_info(

# making few queries to database
ctx_data = get_template_data(
project_entity, folder_entity, task_entity, host_name
project_entity, folder_entity, task_entity, host_name,
settings=project_settings,
username=username
)

# add additional data
Expand Down
13 changes: 10 additions & 3 deletions client/ayon_core/pipeline/template_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ayon_core.lib.local_settings import get_ayon_username


def get_general_template_data(settings=None):
def get_general_template_data(settings=None, username=None):
"""General template data based on system settings or machine.
Output contains formatting keys:
Expand All @@ -14,17 +14,22 @@ def get_general_template_data(settings=None):
Args:
settings (Dict[str, Any]): Studio or project settings.
username (Optional[str]): AYON Username.
"""

if not settings:
settings = get_studio_settings()

if username is None:
username = get_ayon_username()

core_settings = settings["core"]
return {
"studio": {
"name": core_settings["studio_name"],
"code": core_settings["studio_code"]
},
"user": get_ayon_username()
"user": username
}


Expand Down Expand Up @@ -145,6 +150,7 @@ def get_template_data(
task_entity=None,
host_name=None,
settings=None,
username=None
):
"""Prepare data for templates filling from entered documents and info.
Expand All @@ -167,12 +173,13 @@ def get_template_data(
host_name (Optional[str]): Used to fill '{app}' key.
settings (Union[Dict, None]): Prepared studio or project settings.
They're queried if not passed (may be slower).
username (Optional[str]): AYON Username.
Returns:
Dict[str, Any]: Data prepared for filling workdir template.
"""

template_data = get_general_template_data(settings)
template_data = get_general_template_data(settings, username=username)
template_data.update(get_project_template_data(project_entity))
if folder_entity:
template_data.update(get_folder_template_data(
Expand Down

0 comments on commit 1041fc7

Please sign in to comment.