Skip to content

Commit

Permalink
More efficiently clean analysis journal
Browse files Browse the repository at this point in the history
Use IN clause to remove analysis journal database entries instead of
multiple DELETEs.
  • Loading branch information
michaelweiser committed Sep 28, 2018
1 parent 8c1440d commit ff43a2f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions peekaboo/db.py
Expand Up @@ -406,14 +406,19 @@ def clear_in_progress(self):
AnalysisResult,
name='inProgress'
)
in_progress_samples = session.query(SampleInfo).filter_by(
result=in_progress
).all()
for in_progress_sample in in_progress_samples:
session.query(AnalysisJournal).filter_by(
sample=in_progress_sample
).delete()
session.query(SampleInfo).filter_by(result=in_progress).delete()
in_progress_samples = session.query(SampleInfo).filter_by(result=in_progress)
# The direct approach does not work currently with message:
# in_() not yet supported for relationships. For a simple many-to-one,
# use in_() against the set of foreign key values.
# This is what we do below.
#session.query(AnalysisJournal).filter(
# AnalysisJournal.sample.in_(in_progress_samples)).delete()
sample_ids = [s.id for s in in_progress_samples.all()]
if sample_ids:
session.query(AnalysisJournal).filter(
AnalysisJournal.sample_id.in_(sample_ids)
).delete(synchronize_session = False)
in_progress_samples.delete()
try:
session.commit()
logger.debug('Cleared the database from "inProgress" entries.')
Expand Down

0 comments on commit ff43a2f

Please sign in to comment.