Skip to content

Commit

Permalink
[db] Faster query for comment garbage collection
Browse files Browse the repository at this point in the history
Rephrasing a query so it doesn't esceed the statement timeout.
Special thanks to @cservakt!
  • Loading branch information
bruntib committed Jun 3, 2024
1 parent e2037fa commit 1e5d423
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 1e5d423

Please sign in to comment.