-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove unnecessary database queries #1324
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1185,27 +1185,27 @@ def remove_job(self, job_specifier, _unprotect=False): | |
if isinstance(job_specifier, (list, np.ndarray)): | ||
for job_id in job_specifier: | ||
self.remove_job(job_specifier=job_id, _unprotect=_unprotect) | ||
else: | ||
if not self.db.view_mode: | ||
try: | ||
job = self.inspect(job_specifier=job_specifier) | ||
if job is None: | ||
state.logger.warning( | ||
"Job '%s' does not exist and could not be removed", | ||
str(job_specifier), | ||
) | ||
elif _unprotect: | ||
job.remove_child() | ||
else: | ||
job.remove() | ||
except IOError as _: | ||
state.logger.debug( | ||
"hdf file does not exist. Removal from database will be attempted." | ||
) | ||
job_id = self.get_job_id(job_specifier) | ||
self.db.delete_item(job_id) | ||
return | ||
if self.db.view_mode: | ||
raise EnvironmentError("copy_to: is not available in Viewermode !") | ||
job = self.inspect(job_specifier=job_specifier) | ||
if job is None: | ||
state.logger.warning( | ||
"Job '%s' does not exist and could not be removed", | ||
str(job_specifier), | ||
) | ||
return | ||
try: | ||
if _unprotect: | ||
job.remove_child() | ||
else: | ||
raise EnvironmentError("copy_to: is not available in Viewermode !") | ||
job.remove() | ||
except IOError as _: | ||
state.logger.debug( | ||
"hdf file does not exist. Removal from database will be attempted." | ||
) | ||
self.db.delete_item(job.id) | ||
|
||
|
||
def remove_jobs(self, recursive=False, progress=True, silently=False): | ||
""" | ||
|
@@ -1700,23 +1700,19 @@ def _remove_jobs_helper(self, recursive=False, progress=True): | |
""" | ||
if not isinstance(recursive, bool): | ||
raise ValueError("recursive must be a boolean") | ||
if not self.db.view_mode: | ||
job_id_lst = self.get_job_ids(recursive=recursive) | ||
if progress and len(job_id_lst) > 0: | ||
job_id_lst = tqdm(job_id_lst) | ||
for job_id in job_id_lst: | ||
if job_id not in self.get_job_ids(recursive=recursive): | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand this pull request correctly, then the primary change is removing this database query, correct? Maybe we should split this pull request in two parts. One containing just the removal of this part and the other the refactoring. Having both mixed makes it a bit hard to read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
else: | ||
try: | ||
self.remove_job(job_specifier=job_id) | ||
state.logger.debug("Remove job with ID {0} ".format(job_id)) | ||
except (IndexError, Exception): | ||
state.logger.debug( | ||
"Could not remove job with ID {0} ".format(job_id) | ||
) | ||
else: | ||
if self.db.view_mode: | ||
raise EnvironmentError("copy_to: is not available in Viewermode !") | ||
job_id_lst = self.get_job_ids(recursive=recursive) | ||
job_id_progress = tqdm(job_id_lst) if progress else job_id_lst | ||
for job_id in job_id_progress: | ||
try: | ||
self.remove_job(job_specifier=job_id) | ||
state.logger.debug("Remove job with ID {0} ".format(job_id)) | ||
except (IndexError, Exception): | ||
state.logger.debug( | ||
"Could not remove job with ID {0} ".format(job_id) | ||
) | ||
|
||
|
||
def _remove_files(self, pattern="*"): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jan-janssen You missed this line. It might not be called often but it is another redundant database query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is dangerous. For example when you create a job object and remove the HDF5 file, then the loading of the job object with
inspect()
fails and returns anIOError
still in the except case the job object is not available, so we cannot usejob.id
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I realised that the
inspect()
function also works when the file is corrupted #1327