Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Reordering the caching rules
Browse files Browse the repository at this point in the history
Change-Id: Ic2abcf516f340682056a581d74604aa1c8d76430
  • Loading branch information
Mohan Madhavan committed Aug 31, 2016
1 parent 414261a commit 67a259e
Show file tree
Hide file tree
Showing 2 changed files with 441 additions and 431 deletions.
31 changes: 20 additions & 11 deletions poppy/provider/akamai/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,29 @@ def __init__(self, driver):
self.san_cert_hostname_limit = self.driver.san_cert_hostname_limit

def reorder_rules(self, post_data):
ordered_dict = {}
sorted_map = None
wildcard_dict = {}
non_wildcard_dict = {}
ordered_list = []
sorted_wildcard_map = []
sorted_nonwildcard_map = []
if post_data['rules']:
for k, v in enumerate(post_data['rules']):
if v['matches'][0]['value']:
ordered_dict[k] = \
len(v['matches'][0]['value'].split('/'))
sorted_map = sorted(ordered_dict.items(), key=lambda x: x[1],
reverse=True)
for val in sorted_map:
if val[0] != 0:
ordered_list.append(post_data['rules'][val[0]])
ordered_list.append(post_data['rules'][0])
st = v['matches'][0]['value']
if st:
tokens = st.split('/')
if '*' in st:
wildcard_dict[k] = len(tokens)
else:
non_wildcard_dict[k] = len(tokens)
sorted_wildcard_map = sorted(wildcard_dict.items(),
key=lambda x: x[1],
reverse=False)
sorted_nonwildcard_map = sorted(non_wildcard_dict.items(),
key=lambda x: x[1],
reverse=False)
sorted_wildcard_map.extend(sorted_nonwildcard_map)
for val in sorted_wildcard_map:
ordered_list.append(post_data['rules'][val[0]])
return ordered_list

def create(self, service_obj):
Expand Down

0 comments on commit 67a259e

Please sign in to comment.