Skip to content

Commit

Permalink
fix: remove_reports without back-reference to __report_server
Browse files Browse the repository at this point in the history
  • Loading branch information
whisperity committed Aug 24, 2024
1 parent 2a52036 commit fc4ff0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
6 changes: 2 additions & 4 deletions web/server/codechecker_server/api/mass_store_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,10 +1577,8 @@ def get_skip_handler(
report.fixed_at = run_history_time

if reports_to_delete:
# FIXME: This is not usable here, because we no longer have the
# back-reference to a "report_server".
self.__report_server._removeReports(
session, list(reports_to_delete))
from .report_server import remove_reports
remove_reports(session, reports_to_delete)

def finish_checker_run(
self,
Expand Down
26 changes: 14 additions & 12 deletions web/server/codechecker_server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from copy import deepcopy
from collections import OrderedDict, defaultdict, namedtuple
from datetime import datetime
from typing import Any, Dict, List, Optional, Set, Tuple
from typing import Any, Collection, Dict, List, Optional, Set, Tuple

import sqlalchemy
from sqlalchemy.sql.expression import or_, and_, not_, func, \
Expand Down Expand Up @@ -1339,6 +1339,18 @@ def get_is_opened_case(subquery):
)


def remove_reports(session: DBSession,
report_ids: Collection,
chunk_size: int = SQLITE_MAX_VARIABLE_NUMBER):
"""
Removes `Report`s in chunks.
"""
for r_ids in util.chunks(iter(report_ids), chunk_size):
session.query(Report) \
.filter(Report.id.in_(r_ids)) \
.delete(synchronize_session=False)


class ThriftRequestHandler:
"""
Connect to database and handle thrift client requests.
Expand Down Expand Up @@ -3570,16 +3582,6 @@ def removeRunResults(self, run_ids):
failed = True
return not failed

def _removeReports(self, session, report_ids,
chunk_size=SQLITE_MAX_VARIABLE_NUMBER):
"""
Removing reports in chunks.
"""
for r_ids in util.chunks(iter(report_ids), chunk_size):
session.query(Report) \
.filter(Report.id.in_(r_ids)) \
.delete(synchronize_session=False)

@exc_to_thrift_reqfail
@timeit
def removeRunReports(self, run_ids, report_filter, cmp_data):
Expand Down Expand Up @@ -3609,7 +3611,7 @@ def removeRunReports(self, run_ids, report_filter, cmp_data):

reports_to_delete = [r[0] for r in q]
if reports_to_delete:
self._removeReports(session, reports_to_delete)
remove_reports(session, reports_to_delete)

session.commit()
session.close()
Expand Down

0 comments on commit fc4ff0c

Please sign in to comment.