Skip to content

Commit

Permalink
Change/fix use of dict.values to dict.items.
Browse files Browse the repository at this point in the history
Ensuring that dataservice service.py uses items() function rather than
values().
  • Loading branch information
robertbartel authored and aaraney committed Jan 30, 2024
1 parent 9d27ae8 commit abc684f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/services/dataservice/dmod/dataservice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _get_ds_users(self) -> Dict[UUID, DatasetUser]:
Map of all ::class:`DatasetUser` from all associated managers of the service, keyed by the UUID of each.
"""
return {uuid: mgr.get_dataset_user(uuid)
for _, mgr in self._all_data_managers.values() for uuid in mgr.get_dataset_user_ids()}
for _, mgr in self._all_data_managers.items() for uuid in mgr.get_dataset_user_ids()}

def _process_dataset_create(self, message: DatasetManagementMessage) -> DatasetManagementResponse:
"""
Expand Down Expand Up @@ -674,10 +674,10 @@ def _temp_dataset_mark_and_sweep(self):
next invocation).
"""
# Get these upfront, since no meaningful changes can happen during the course of an iteration
temp_datasets = {ds_name: ds for ds_name, ds in self.get_known_datasets().values() if ds.is_temporary}
temp_datasets = {ds_name: ds for ds_name, ds in self.get_known_datasets().items() if ds.is_temporary}

# Account for any in-use temporary datasets by potentially unmarking and updating expire time
for ds in (ds for _, ds in temp_datasets.values() if ds.manager.get_user_ids_for_dataset(ds)):
for ds in (ds for _, ds in temp_datasets.items() if ds.manager.get_user_ids_for_dataset(ds)):
if ds.name in self._marked_expired_datasets:
self._marked_expired_datasets.remove(ds.name)

Expand All @@ -689,7 +689,7 @@ def _temp_dataset_mark_and_sweep(self):
ds.manager.delete(dataset=ds)

# Mark any expired datasets for deletion on the next iteration
self._marked_expired_datasets.update(n for n, ds in temp_datasets.values() if ds.expires > datetime.now())
self._marked_expired_datasets.update(n for n, ds in temp_datasets.items() if ds.expires > datetime.now())

def _unlink_finished_jobs(self, ds_users: Dict[UUID, DatasetUser]) -> Set[UUID]:
"""
Expand All @@ -711,7 +711,7 @@ def _unlink_finished_jobs(self, ds_users: Dict[UUID, DatasetUser]) -> Set[UUID]:
"""
finished_job_users: Set[UUID] = set()
active_job_ids = {UUID(j.job_id) for j in self._job_util.get_all_active_jobs()}
for user in (u for uid, u in ds_users.values() if isinstance(u, JobDatasetUser) and uid not in active_job_ids):
for user in (u for uid, u in ds_users.items() if isinstance(u, JobDatasetUser) and uid not in active_job_ids):
for ds in (self.get_known_datasets()[ds_name] for ds_name in user.datasets_and_managers):
user.unlink_to_dataset(ds)
finished_job_users.add(user.uuid)
Expand Down

0 comments on commit abc684f

Please sign in to comment.