From dad86242a9f3c2e5227af6d5c47323065951af0e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 22 Sep 2017 10:06:02 -0400 Subject: [PATCH] Performance optimize abbreviation Don't abbreviate the same nodes twice when we don't have to. --- confluent_client/confluent/textgroup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/confluent_client/confluent/textgroup.py b/confluent_client/confluent/textgroup.py index 18556d05..d1a87523 100644 --- a/confluent_client/confluent/textgroup.py +++ b/confluent_client/confluent/textgroup.py @@ -96,6 +96,7 @@ class GroupedData(object): def __init__(self, confluentconnection=None): self.bynode = {} self.byoutput = {} + self.header = {} self.client = confluentconnection def generate_byoutput(self): @@ -115,9 +116,14 @@ class GroupedData(object): def get_group_text(self, nodes): if self.client: + headerkey = ','.join(sorted(nodes)) + if headerkey in self.header: + return self.header[headerkey] noderange = '' - for reply in self.client.create('/noderange//abbreviate', {'nodes': sorted(nodes)}): + for reply in self.client.create('/noderange//abbreviate', + {'nodes': sorted(nodes)}): noderange = reply['noderange'] + self.header[headerkey] = noderange return noderange else: return ','.join(sorted(nodes, key=humanify_nodename))