Skip to content

Commit

Permalink
listmetadatatypes and listchanges are made in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi2506 committed Feb 5, 2024
1 parent ff5fa4b commit 89c5c60
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
81 changes: 55 additions & 26 deletions metecho/api/jobs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import concurrent.futures
import contextlib
import logging
import string
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/js/components/tasks/retrieveMetadata/changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down

0 comments on commit 89c5c60

Please sign in to comment.