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

Commit dd0f85d

Browse files
committed
Optimize usage of match
This creates stateful `Matcher`s instead, to avoid re-compiling regex matchers in loops.
1 parent ca99ee9 commit dd0f85d

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

compare/commands/compare/interactors/fetch_impacted_files.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import enum
22
from typing import List, Optional
33

4-
from shared.utils.match import match
4+
from shared.utils.match import Matcher
55

66
import services.components as components
77
from codecov.commands.base import BaseInteractor
@@ -74,11 +74,8 @@ def _apply_filters(
7474
res = impacted_files
7575

7676
if components_paths:
77-
res = [
78-
file
79-
for file in impacted_files
80-
if match(components_paths, file.head_name)
81-
]
77+
matcher = Matcher(components_paths)
78+
res = [file for file in impacted_files if matcher.match(file.head_name)]
8279
return res
8380

8481
def get_attribute(

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ freezegun
2525
google-cloud-pubsub
2626
gunicorn>=22.0.0
2727
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
28-
https://github.com/codecov/shared/archive/7ba099fa0552244c77a8cc3a4b772216613c09c8.tar.gz#egg=shared
28+
https://github.com/codecov/shared/archive/3aea532ed80c4d941cbc50e27b11147a8f72d3cd.tar.gz#egg=shared
2929
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz
3030
idna>=3.7
3131
minio

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ sentry-sdk[celery]==2.13.0
416416
# shared
417417
setproctitle==1.1.10
418418
# via -r requirements.in
419-
shared @ https://github.com/codecov/shared/archive/7ba099fa0552244c77a8cc3a4b772216613c09c8.tar.gz
419+
shared @ https://github.com/codecov/shared/archive/3aea532ed80c4d941cbc50e27b11147a8f72d3cd.tar.gz
420420
# via -r requirements.in
421421
simplejson==3.17.2
422422
# via -r requirements.in

services/path.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from shared.reports.resources import Report
1212
from shared.reports.types import ReportTotals
1313
from shared.torngit.exceptions import TorngitClientError
14-
from shared.utils.match import match
14+
from shared.utils.match import Matcher
1515

1616
import services.report as report_service
1717
from codecov_auth.models import Owner
@@ -195,7 +195,8 @@ def files(self) -> list[str]:
195195

196196
# Do path filtering if needed
197197
if self.filter_paths:
198-
files = [file for file in files if match(self.filter_paths, file)]
198+
matcher = Matcher(self.filter_paths)
199+
files = [file for file in files if matcher.match(file)]
199200

200201
return files
201202

0 commit comments

Comments
 (0)