diff --git a/metecho/api/jobs.py b/metecho/api/jobs.py index 641277a15..bd00b7a6e 100644 --- a/metecho/api/jobs.py +++ b/metecho/api/jobs.py @@ -1,3 +1,4 @@ +import concurrent.futures import contextlib import logging import string @@ -277,8 +278,9 @@ def create_repository( else: repo = org.create_repository( - project.repo_name, description=project.description, - private=settings.ENABLE_CREATE_PRIVATE_REPO + project.repo_name, + description=project.description, + private=settings.ENABLE_CREATE_PRIVATE_REPO, ) team.add_repository(repo.full_name, permission="push") project.repo_id = repo.id @@ -608,33 +610,60 @@ def refresh_scratch_org(scratch_org, *, originating_user_id): refresh_scratch_org_job = job(refresh_scratch_org) +def unsaved_changes(scratch_org, originating_user_id): + old_revision_numbers = scratch_org.latest_revision_numbers + + new_revision_numbers = get_latest_revision_numbers( + scratch_org, originating_user_id=originating_user_id + ) + unsaved_changes = compare_revisions(old_revision_numbers, new_revision_numbers) + user = scratch_org.owner + repo_id = scratch_org.parent.get_repo_id() + commit_ish = scratch_org.parent.branch_name + + with local_github_checkout(user, repo_id, commit_ish) as repo_root: + scratch_org.valid_target_directories, _ = get_valid_target_directories( + user, + scratch_org, + repo_root, + ) + scratch_org.unsaved_changes = unsaved_changes + + +def nonsource_types(scratch_org): + with dataset_env(scratch_org) as ( + project_config, + org_config, + sf, + schema, + repo, + ): + components = ListNonSourceTrackable( + org_config=org_config, + project_config=project_config, + task_config=TaskConfig({"options": {}}), + )() + scratch_org.non_source_changes = {} + for types in components: + scratch_org.non_source_changes[types] = [] + + def get_unsaved_changes(scratch_org, *, originating_user_id): + try: - scratch_org.refresh_from_db() - old_revision_numbers = scratch_org.latest_revision_numbers - new_revision_numbers = get_latest_revision_numbers( - scratch_org, originating_user_id=originating_user_id - ) - unsaved_changes = compare_revisions(old_revision_numbers, new_revision_numbers) - user = scratch_org.owner - repo_id = scratch_org.parent.get_repo_id() - commit_ish = scratch_org.parent.branch_name - with local_github_checkout(user, repo_id, commit_ish) as repo_root: - scratch_org.valid_target_directories, _ = get_valid_target_directories( - user, - scratch_org, - repo_root, + with concurrent.futures.ThreadPoolExecutor() as executor: + unsaved_changes_result = executor.submit( + unsaved_changes, + scratch_org=scratch_org, + originating_user_id=originating_user_id, ) - scratch_org.unsaved_changes = unsaved_changes - with dataset_env(scratch_org) as (project_config, org_config, sf, schema, repo): - components = ListNonSourceTrackable( - org_config=org_config, - project_config=project_config, - task_config=TaskConfig({"options": {}}), - )() - scratch_org.non_source_changes = {} - for types in components: - scratch_org.non_source_changes[types] = [] + nonsource_types_result = executor.submit( + nonsource_types, scratch_org=scratch_org + ) + concurrent.futures.wait([unsaved_changes_result, nonsource_types_result]) + unsaved_changes_result.result() + nonsource_types_result.result() + except Exception as e: scratch_org.refresh_from_db() scratch_org.finalize_get_unsaved_changes( diff --git a/src/js/components/tasks/retrieveMetadata/changes.tsx b/src/js/components/tasks/retrieveMetadata/changes.tsx index 62d7dd8b2..e7cdbf5a9 100644 --- a/src/js/components/tasks/retrieveMetadata/changes.tsx +++ b/src/js/components/tasks/retrieveMetadata/changes.tsx @@ -197,6 +197,7 @@ const ChangesForm = ({ }); const metadata_type = groupName.match(/changes-(.+)/)?.[1]; if ( + metadata_type !== undefined && expandedPanels[groupName] === undefined && metadatachanges[metadata_type].length == 0 ) {