Skip to content

Commit

Permalink
Merge pull request Ericsson#4254 from bruntib/cleanup_comments
Browse files Browse the repository at this point in the history
[db] Faster query for comment garbage collection
  • Loading branch information
bruntib authored Jun 4, 2024
2 parents 0610134 + 1e5d423 commit bddbdf7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions web/server/codechecker_server/database/db_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ def remove_unused_comments(product):
LOG.debug("[%s] Garbage collection of dangling comments started...",
product.endpoint)
try:
report_hashes = session.query(Report.bug_id) \
.group_by(Report.bug_id) \
sub = session.query(Comment.id) \
.join(Report,
Comment.bug_hash == Report.bug_id,
isouter=True) \
.filter(Report.id.is_(None)) \
.subquery()

count = session.query(Comment) \
.filter(Comment.bug_hash.notin_(report_hashes)) \
.filter(Comment.id.in_(sub)) \
.delete(synchronize_session=False)
if count:
LOG.debug("%d dangling comments deleted.", count)
Expand Down

0 comments on commit bddbdf7

Please sign in to comment.