Skip to content

Commit 5453668

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

2 files changed

Lines changed: 19 additions & 7 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: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pathspec
88

9-
from odoo import fields, models
9+
from odoo import fields, models, tools
1010
from odoo.fields import Command
1111

1212
_logger = logging.getLogger(__name__)
@@ -32,19 +32,27 @@ 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.browse()._call_cloc_command(
53+
record.id, record.local_path
54+
)
55+
parameters["cloc"] = cloc_response
4856
matches = self._cloc_get_matches(record.local_path)
4957
cloc_data = self._action_analysis_process_cloc(
5058
record.local_path, matches, cloc_response
@@ -94,7 +102,8 @@ def _action_analysis_process_cloc(self, path, matchs, cloc_response):
94102
res["empty"] += res_file["blank"]
95103
return res
96104

97-
def _call_cloc_command(self, local_path):
105+
@tools.ormcache("record_id", "local_path")
106+
def _call_cloc_command(self, record_id, local_path):
98107
res = check_output(["cloc", "--by-file", "--json", local_path])
99108
return json.loads(res)
100109

0 commit comments

Comments
 (0)