Skip to content

Commit

Permalink
[2237] speed up tests by makeing metadata modified faster
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Mar 21, 2012
1 parent 590962d commit 257bf05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
5 changes: 5 additions & 0 deletions ckan/lib/dictization/__init__.py
Expand Up @@ -46,6 +46,11 @@ def table_dictize(obj, context, **kw):

result_dict.update(kw)

##HACK For optimisation to get metadata_modified created faster.

context['metadata_modified'] = max(result_dict.get('revision_timestamp', ''),
context.get('metadata_modified', ''))

return result_dict


Expand Down
18 changes: 5 additions & 13 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -40,9 +40,10 @@ def resource_list_dictize(res_list, context):
active = context.get('active', True)
result_list = []
for res in res_list:
resource_dict = resource_dictize(res, context)
if active and res.state not in ('active', 'pending'):
continue
result_list.append(resource_dictize(res, context))
result_list.append(resource_dict)

return sorted(result_list, key=lambda x: x["position"])

Expand All @@ -65,9 +66,9 @@ def extras_list_dictize(extras_list, context):
result_list = []
active = context.get('active', True)
for extra in extras_list:
dictized = d.table_dictize(extra, context)
if active and extra.state not in ('active', 'pending'):
continue
dictized = d.table_dictize(extra, context)
value = dictized["value"]
if not(context.get("extras_as_string") and isinstance(value, basestring)):
dictized["value"] = h.json.dumps(value)
Expand Down Expand Up @@ -205,11 +206,10 @@ def package_dictize(pkg, context):
result_dict['license_title']= pkg.license_id

# creation and modification date
result_dict['metadata_modified'] = pkg.metadata_modified.isoformat() \
if pkg.metadata_modified else None
result_dict['metadata_modified'] = context.pop('metadata_modified')
result_dict['metadata_created'] = pkg.metadata_created.isoformat() \
if pkg.metadata_created else None

if context.get('for_view'):
for item in plugins.PluginImplementations(plugins.IPackageController):
result_dict = item.before_view(result_dict)
Expand Down Expand Up @@ -366,14 +366,6 @@ def package_to_api(pkg, context):
if site_url:
dictized['ckan_url'] = '%s/dataset/%s' % (site_url, pkg.name)

metadata_modified = pkg.metadata_modified
dictized['metadata_modified'] = metadata_modified.isoformat() \
if metadata_modified else None

metadata_created = pkg.metadata_created
dictized['metadata_created'] = metadata_created.isoformat() \
if metadata_created else None

for resource in dictized["resources"]:
resource_dict_to_api(resource, pkg.id, context)

Expand Down
6 changes: 3 additions & 3 deletions ckan/model/package.py
Expand Up @@ -584,12 +584,12 @@ def get_groups(self, group_type=None, capacity=None):
@property
def metadata_created(self):
import ckan.model as model
q = model.Session.query(model.PackageRevision)\
q = model.Session.query(model.PackageRevision.revision_timestamp)\
.filter(model.PackageRevision.id == self.id)\
.order_by(model.PackageRevision.revision_timestamp.asc())
ts = q.first()
if ts is not None:
return ts.revision_timestamp
if ts:
return ts[0]

@staticmethod
def get_fields(core_only=False, fields_to_ignore=None):
Expand Down

0 comments on commit 257bf05

Please sign in to comment.