Skip to content

Commit

Permalink
use workspace as a key for scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Feb 6, 2025
1 parent 37366ec commit ca3b848
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,16 @@ def sync_studies_on_disk(
all_studies = [raw_study for raw_study in all_studies if directory in Path(raw_study.path).parents]
else:
all_studies = [raw_study for raw_study in all_studies if directory == Path(raw_study.path).parent]
studies_by_path = {study.path: study for study in all_studies}
studies_by_path_workspace = {(study.workspace, study.path): study for study in all_studies}

# delete orphan studies on database
paths = [str(f.path) for f in folders]
workspace_paths = [(f.workspace, str(f.path)) for f in folders]

for study in all_studies:
if (
isinstance(study, RawStudy)
and not study.archived
and (study.workspace != DEFAULT_WORKSPACE_NAME and study.path not in paths)
and (study.workspace != DEFAULT_WORKSPACE_NAME and (study.workspace, study.path) not in workspace_paths)
):
if not study.missing:
logger.info(
Expand All @@ -919,11 +919,12 @@ def sync_studies_on_disk(
self.repository.delete(study.id)

# Add new studies
study_paths = [study.path for study in all_studies if study.missing is None]
study_paths = [(study.workspace, study.path) for study in all_studies if study.missing is None]
missing_studies = {study.path: study for study in all_studies if study.missing is not None}
for folder in folders:
study_path = str(folder.path)
if study_path not in study_paths:
workspace = folder.workspace
if (workspace, study_path) not in study_paths:
try:
if study_path not in missing_studies.keys():
base_path = self.config.storage.workspaces[folder.workspace].path
Expand All @@ -933,7 +934,7 @@ def sync_studies_on_disk(
name=folder.path.name,
path=study_path,
folder=str(dir_name),
workspace=folder.workspace,
workspace=workspace,
owner=None,
groups=folder.groups,
public_mode=PublicMode.FULL if len(folder.groups) == 0 else PublicMode.NONE,
Expand Down Expand Up @@ -968,8 +969,8 @@ def sync_studies_on_disk(
)
except Exception as e:
logger.error(f"Failed to add study {folder.path}", exc_info=e)
elif directory and study_path in studies_by_path:
existing_study = studies_by_path[study_path]
elif directory and (workspace, study_path) in studies_by_path_workspace:
existing_study = studies_by_path_workspace[(workspace, study_path)]
if self.storage_service.raw_study_service.update_name_and_version_from_raw_meta(existing_study):
self.repository.save(existing_study)

Expand Down

0 comments on commit ca3b848

Please sign in to comment.