Commit 6730dc77 authored by Vincent Pelletier's avatar Vincent Pelletier

It's faster (O(1) instead of O(n)) to search a value in dict keys that in a...

It's faster (O(1) instead of O(n)) to search a value in dict keys that in a list, so use dict when possible.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15908 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cf5ce6c5
...@@ -1900,7 +1900,6 @@ class Catalog( Folder, ...@@ -1900,7 +1900,6 @@ class Catalog( Folder,
kw = REQUEST kw = REQUEST
acceptable_key_map = self.getColumnMap() acceptable_key_map = self.getColumnMap()
acceptable_keys = acceptable_key_map.keys()
full_text_search_keys = list(self.sql_catalog_full_text_search_keys) full_text_search_keys = list(self.sql_catalog_full_text_search_keys)
keyword_search_keys = list(self.sql_catalog_keyword_search_keys) keyword_search_keys = list(self.sql_catalog_keyword_search_keys)
topic_search_keys = self.sql_catalog_topic_search_keys topic_search_keys = self.sql_catalog_topic_search_keys
...@@ -2008,7 +2007,7 @@ class Catalog( Folder, ...@@ -2008,7 +2007,7 @@ class Catalog( Folder,
# Define related maps # Define related maps
# each tuple from `related_tuples` has the form (key, # each tuple from `related_tuples` has the form (key,
# 'table1,table2,table3/column/where_expression') # 'table1,table2,table3/column/where_expression')
related_keys = [] related_keys = {}
related_method = {} related_method = {}
related_table_map = {} related_table_map = {}
related_column = {} related_column = {}
...@@ -2020,7 +2019,7 @@ class Catalog( Folder, ...@@ -2020,7 +2019,7 @@ class Catalog( Folder,
key = t_tuple[0].strip() key = t_tuple[0].strip()
if key in key_list: if key in key_list:
join_tuple = t_tuple[1].strip().split('/') join_tuple = t_tuple[1].strip().split('/')
related_keys.append(key) related_keys[key] = None
method_id = join_tuple[2] method_id = join_tuple[2]
table_list = tuple(join_tuple[0].split(',')) table_list = tuple(join_tuple[0].split(','))
related_method[key] = method_id related_method[key] = method_id
...@@ -2041,14 +2040,14 @@ class Catalog( Folder, ...@@ -2041,14 +2040,14 @@ class Catalog( Folder,
# We take additional parameters from the REQUEST # We take additional parameters from the REQUEST
# and give priority to the REQUEST # and give priority to the REQUEST
if REQUEST is not None: if REQUEST is not None:
for key in acceptable_keys: for key in acceptable_key_map.iterkeys():
if REQUEST.has_key(key): if REQUEST.has_key(key):
# Only copy a few keys from the REQUEST # Only copy a few keys from the REQUEST
if key in self.sql_catalog_request_keys: if key in self.sql_catalog_request_keys:
kw[key] = REQUEST[key] kw[key] = REQUEST[key]
def getNewKeyAndUpdateVariables(key): def getNewKeyAndUpdateVariables(key):
key_is_acceptable = key in acceptable_keys # Only calculate once key_is_acceptable = key in acceptable_key_map # Only calculate once
key_is_related = key in related_keys key_is_related = key in related_keys
new_key = None new_key = None
if key_is_acceptable or key_is_related: if key_is_acceptable or key_is_related:
...@@ -2068,7 +2067,7 @@ class Catalog( Folder, ...@@ -2068,7 +2067,7 @@ class Catalog( Folder,
new_key = '%s.%s' % (acceptable_key_map[key][0], key) new_key = '%s.%s' % (acceptable_key_map[key][0], key)
# query_table specifies what table name should be used by default # query_table specifies what table name should be used by default
elif query_table and \ elif query_table and \
'%s.%s' % (query_table, key) in acceptable_keys: '%s.%s' % (query_table, key) in acceptable_key_map:
new_key = '%s.%s' % (query_table, key) new_key = '%s.%s' % (query_table, key)
elif key == 'uid': elif key == 'uid':
# uid is always ambiguous so we can only change it here # uid is always ambiguous so we can only change it here
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment