Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit a71b222

Browse files
committed
Do not double-filter Reports in ReportPaths
Previously, the `ReportPaths.files` accessor would manually filter through the `unfiltered_report`. Even though the `self.report` was already filtered. Now the custom filtering logic is a bit updated, but taking care of existing bugs in `FilteredReport`, as that is still yielding files even though they are not matching any `flags`.
1 parent 7c058c9 commit a71b222

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

services/path.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from asgiref.sync import async_to_sync
1010
from django.conf import settings
1111
from shared.reports.resources import Report
12+
from shared.reports.filtered import FilteredReport, FilteredReportFile
1213
from shared.reports.types import ReportTotals
1314
from shared.torngit.exceptions import TorngitClientError
1415
from shared.utils.match import Matcher
@@ -150,13 +151,12 @@ def __init__(
150151
report: Report,
151152
path: str | None = None,
152153
search_term: str | None = None,
153-
filter_flags: list[str] = [],
154-
filter_paths: list[str] = [],
154+
filter_flags: list[str] = None,
155+
filter_paths: list[str] = None,
155156
):
156-
self.report = report
157-
self.unfiltered_report = report
158-
self.filter_flags = filter_flags
159-
self.filter_paths = filter_paths
157+
self.report: Report | FilteredReport = report
158+
self.filter_flags = filter_flags or []
159+
self.filter_paths = filter_paths or []
160160
self.prefix = path or ""
161161

162162
# Filter report if flags or paths exist
@@ -172,37 +172,37 @@ def __init__(
172172
]
173173

174174
if search_term:
175+
search_term = search_term.lower()
175176
self._paths = [
176177
path
177-
for path in self.paths
178-
if search_term.lower() in path.relative_path.lower()
178+
for path in self._paths
179+
if search_term in path.relative_path.lower()
179180
]
180181

181182
@cached_property
182183
def files(self) -> list[str]:
183-
# No filtering, just return files in Report
184-
if not self.filter_flags and not self.filter_paths:
184+
# No flags filtering, just return (path-filtered) files in Report
185+
if not self.filter_flags:
185186
return self.report.files
186187

188+
# When there is a flag filter, `FilteredReport` currently yields
189+
# `FilteredReportFile`s without actually checking whether they match the sessions.
190+
# Before that bug is fixed, lets do the filtering manually here. Once that bug is fixed,
191+
# this should just forward to `self.report.files` like above.
187192
files = []
188-
# Do flag filtering if needed
189-
if self.filter_flags:
190-
files = report_service.files_belonging_to_flags(
191-
commit_report=self.unfiltered_report, flags=self.filter_flags
192-
)
193-
else:
194-
files = [file.name for file in self.unfiltered_report]
195-
196-
# Do path filtering if needed
197-
if self.filter_paths:
198-
matcher = Matcher(self.filter_paths)
199-
files = [file for file in files if matcher.match(file)]
200-
193+
for file in self.report:
194+
if isinstance(file, FilteredReportFile):
195+
found = False
196+
for _ln, line in self.report_file.lines:
197+
if line and any(s.id in file.session_ids for s in line.sessions):
198+
found = True
199+
break
200+
if not found:
201+
continue
202+
203+
files.append(file.name)
201204
return files
202205

203-
def _filter_commit_report(self) -> None:
204-
self.report = self.report.filter(flags=self.filter_flags)
205-
206206
@property
207207
def paths(self) -> list[PrefixedPath]:
208208
return self._paths

0 commit comments

Comments
 (0)