Skip to content

Commit

Permalink
speed up for compare domain code
Browse files Browse the repository at this point in the history
It now runs only up to a point where it is sure that the domains are not the same which speeds up comparison in some cases.
  • Loading branch information
domoritz committed Nov 24, 2012
1 parent 48eca99 commit 451571c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ckan/lib/helpers.py
Expand Up @@ -1269,16 +1269,21 @@ def format_resource_items(items):
def _compare_domains(urls):
''' Return True if the domains of the provided are the same.
'''
domains = set()
first_domain = None
for url in urls:
# all urls are interpreted as absolute urls,
# except for urls that start with a /
if not urlparse.urlparse(url).scheme and not url.startswith('/'):
url = '//' + url
parsed = urlparse.urlparse(url.lower(), 'http')
domain = (parsed.scheme, parsed.hostname, parsed.port)
domains.add(domain)
return len(domains) == 1

if not first_domain:
first_domain = domain
continue
if first_domain != domain:
return False
return True


def add_whether_on_same_domain(data_dict):
Expand Down

0 comments on commit 451571c

Please sign in to comment.