Commit 56c33d07 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

optimize _getPropertyList and _getCategoryList

* call getters for already stored properties and categories only.
parent 375b9730
...@@ -118,50 +118,31 @@ def _getPropertyAndCategoryList(document): ...@@ -118,50 +118,31 @@ def _getPropertyAndCategoryList(document):
def _getPropertyList(document, acquire=True): def _getPropertyList(document, acquire=True):
property_map = document.getPropertyMap() property_map = document.getPropertyMap()
bad_property_list = ['id', 'uid', 'categories_list', 'last_id',] bad_property_list = ['id', 'uid', 'categories_list', 'last_id',]
# we don't want acquired properties without acquisition_mask_value document_dict = document.__dict__
for x in property_map: property_dict = {}
if x.has_key('acquisition_base_category') and not x.get('acquisition_mask_value', 0):
bad_property_list.append(x['id'])
default_value_dict = dict([(x['id'], x.get('default', None)) \
for x in property_map])
getPropertyList = document.getPropertyList getPropertyList = document.getPropertyList
getProperty = document.getProperty getProperty = document.getProperty
getter_list_type_dict = { for x in property_map:
True:getPropertyList, property_id = x['id']
False:getProperty if property_id in bad_property_list:
} continue
getter_dict = dict([(x['id'], # we care already stored property only
getter_list_type_dict[x['type'] in list_types and not x['id'].endswith('_list')]) \ elif (x['storage_id'] or property_id) not in document_dict:
for x in property_map]) continue
# we don't want acquired properties without acquisition_mask_value
def filter_property_func(x): elif x.has_key('acquisition_base_category') and not x.get('acquisition_mask_value', 0):
key, value = x continue
if key in bad_property_list: elif x['type'] in list_types and not property_id.endswith('_list'):
return False property_dict[property_id] = getPropertyList(property_id)
default = default_value_dict[key] else:
if value == default: property_dict[property_id] = getProperty(property_id)
return False return property_dict
if not acquire and not document.hasProperty(key):
return False
if isinstance(value, (list, tuple)) and \
isinstance(default, (list, tuple)) and \
tuple(value) == tuple(default):
return False
return True
return dict(filter(filter_property_func,
[(x, getter_dict[x](x)) for x in \
document.getPropertyIdList()]))
def _getCategoryList(document, acquire=True): def _getCategoryList(document, acquire=True):
bad_category_list = ['solver', ] bad_category_list = ['solver', ]
# we care already stored category only
document_category_set = set([x.split('/',1)[0] for x in \
document.getCategoryList()])
getPropertyList = document.getPropertyList getPropertyList = document.getPropertyList
def filter_category_func(x): return dict([(x, getPropertyList(x)) for x in document_category_set \
return len(x[1]) != 0 and x[0] not in bad_category_list and \ if x not in bad_category_list])
(acquire or document.hasProperty(x[0]))
return dict(filter(filter_category_func,
[(x, getPropertyList(x)) for x in \
document.getBaseCategoryList()]))
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