Skip to content

Commit a500a23

Browse files
committed
Add pre_filter on count by rules
1 parent ff5cbb6 commit a500a23

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

sonar/issues.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,21 +833,23 @@ def count(endpoint: pf.Platform, **kwargs) -> int:
833833
def count_by_rule(endpoint: pf.Platform, **kwargs) -> dict[str, int]:
834834
"""Returns number of issues of a search"""
835835
params = {} if not kwargs else kwargs.copy()
836+
nbr_slices = 1
837+
SLICE_SIZE = 50 # Search rules facets by bulks of 50
838+
if "rules" in params:
839+
ruleset = params.pop("rules")
840+
nbr_slices = (len(ruleset) + SLICE_SIZE - 1) // SLICE_SIZE
841+
params = pre_search_filters(endpoint=endpoint, params=params)
836842
params["ps"] = 1
837843
params["facets"] = "rules"
838-
SLICE_SIZE = 50 # Search rules facets by bulks of 50
839-
nbr_slices = 1
840844
if "rules" in params:
841-
nbr_slices = (len(params["rules"]) + SLICE_SIZE - 1) // SLICE_SIZE
845+
nbr_slices = (len(ruleset) + SLICE_SIZE - 1) // SLICE_SIZE
842846
rulecount = {}
843847
for i in range(nbr_slices):
844848
sliced_params = params.copy()
845-
sliced_params["rules"] = ",".join(params["rules"][i * SLICE_SIZE : min((i + 1) * SLICE_SIZE - 1, len(params["rules"]))])
846-
# log.debug("COUNT params = %s", str(sliced_params))
849+
sliced_params["rules"] = ",".join(ruleset[i * SLICE_SIZE : min((i + 1) * SLICE_SIZE - 1, len(ruleset))])
847850
data = json.loads(endpoint.get(Issue.SEARCH_API, params=sliced_params).text)["facets"][0]["values"]
848-
# log.debug("COUNT data results = %s", str(data))
849851
for d in data:
850-
if d["val"] not in params["rules"]:
852+
if d["val"] not in ruleset:
851853
continue
852854
if d["val"] not in rulecount:
853855
rulecount[d["val"]] = 0

0 commit comments

Comments
 (0)