Skip to content

Commit

Permalink
[Fix] Getting file counts query
Browse files Browse the repository at this point in the history
Grouping by the file path takes too long when the user wants to filter the reports by file path filter.
The solution can be using `distinct` insted of `group by` to get the first ten files considering the report filter as well. Then it is faster to count the number of reports only for these files..
  • Loading branch information
cservakt committed Jan 10, 2025
1 parent 8421e16 commit 9eaa60e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions web/server/codechecker_server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3425,35 +3425,35 @@ def getFileCounts(self, run_ids, report_filter, cmp_data, limit, offset):
filter_expression, join_tables = process_report_filter(
session, run_ids, report_filter, cmp_data)

extended_table = session.query(
Report.file_id,
Report.bug_id,
Report.id)
distinct_file_path = session.query(File.filepath.distinct()) \
.join(Report, Report.file_id == File.id)

if report_filter.annotations is not None:
extended_table = extended_table.outerjoin(
distinct_file_path = distinct_file_path.outerjoin(
ReportAnnotations,
ReportAnnotations.report_id == Report.id)
extended_table = extended_table.group_by(Report.id)
distinct_file_path = distinct_file_path.group_by(
Report.id)

extended_table = apply_report_filter(
extended_table, filter_expression, join_tables)
distinct_file_path = apply_report_filter(
distinct_file_path, filter_expression, join_tables, [File])

extended_table = extended_table.subquery()
if limit:
distinct_file_path = distinct_file_path.limit(limit) \
.offset(offset)

distinct_file_path = distinct_file_path.subquery()

count_col = extended_table.c.bug_id.distinct() if \
report_filter.isUnique else extended_table.c.bug_id
count_col = Report.bug_id.distinct() if \
report_filter.isUnique else Report.bug_id

stmt = session.query(
File.filepath,
func.count(count_col).label('report_num')) \
.join(
extended_table, File.id == extended_table.c.file_id) \
.group_by(File.filepath) \
.order_by(desc('report_num'))

if limit:
stmt = stmt.limit(limit).offset(offset)
Report, Report.file_id == File.id) \
.filter(File.filepath.in_(distinct_file_path)) \
.group_by(File.filepath)

for fp, count in stmt:
results[fp] = count
Expand Down

0 comments on commit 9eaa60e

Please sign in to comment.