Skip to content

Commit 5d1f542

Browse files
committed
[IMP] vcp_management: Pass some parameters to speed things a little
1 parent 13d91db commit 5d1f542

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

vcp_management/models/vcp_repository_branch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ def _get_local_path(self):
6565
def process_rules(self):
6666
for record in self:
6767
rules = record._get_rules()
68+
# This parameters dict can be used to store parameters that will
69+
# be used by other rules.
70+
parameters = {}
6871
for rule in rules:
6972
if re.match(rule.branch_pattern, record.branch_id.name):
70-
rule._process_rule(record)
73+
rule._process_rule(record, parameters)
7174

7275
def _download_code(self):
7376
result = super()._download_code()

vcp_management/models/vcp_rule.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ class VcpRule(models.Model):
3232
default="cloc",
3333
)
3434

35-
def _process_rule(self, record):
35+
def _process_rule(self, record, parameters=None):
3636
"""
3737
Process the rule on the given repository and branch.
3838
It will call the corresponding method based on the rule type.
3939
"""
40-
return getattr(self, f"_process_rule_{self.rule_type}")(record)
40+
return getattr(self, f"_process_rule_{self.rule_type}")(record, parameters)
4141

42-
def _process_rule_cloc(self, record):
42+
def _process_rule_cloc(self, record, parameters=None):
4343
"""
4444
Process the rule as a cloc analysis.
4545
"""
4646
record._download_code()
47-
cloc_response = self._call_cloc_command(record.local_path)
47+
if parameters is None:
48+
parameters = {}
49+
if "cloc" in parameters:
50+
cloc_response = parameters["cloc"]
51+
else:
52+
cloc_response = self._call_cloc_command(record.local_path)
53+
parameters["cloc"] = cloc_response
4854
matches = self._cloc_get_matches(record.local_path)
4955
cloc_data = self._action_analysis_process_cloc(
5056
record.local_path, matches, cloc_response

0 commit comments

Comments
 (0)