Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix performance issue when exporting many groups #3681

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions aiida/tools/importexport/dbexport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,37 @@ def export_tree(
)

# Add all the nodes contained within the specified groups
for group in given_groups:
for entry in group.nodes:
entities_starting_set[NODE_ENTITY_NAME].add(entry.uuid)
if issubclass(entry.__class__, orm.Data):
given_data_entry_ids.add(entry.pk)
elif issubclass(entry.__class__, orm.ProcessNode):
given_calculation_entry_ids.add(entry.pk)
if given_group_entry_ids:

if not silent:
print('RETRIEVING NODES FROM GROUPS...')

# Use single query instead of given_group.nodes iterator for performance.
qh_groups = orm.QueryBuilder().append(
orm.Group, filters={
'id': {
'in': given_group_entry_ids
}
}, tag='groups'
).queryhelp

# Delete this import once the dbexport.zip module has been renamed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future: This should be changed in #3242

from builtins import zip # pylint: disable=redefined-builtin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this I get an error that zip is a module and not callable ( we have a module called zip in the same folder).
If you want me to rename the module instead, let me know.


data_results = orm.QueryBuilder(**qh_groups).append(orm.Data, project=['id', 'uuid'], with_group='groups').all()
if data_results:
pks, uuids = map(list, zip(*data_results))
entities_starting_set[NODE_ENTITY_NAME].update(uuids)
given_data_entry_ids.update(pks)
del data_results, pks, uuids

calc_results = orm.QueryBuilder(**qh_groups
).append(orm.ProcessNode, project=['id', 'uuid'], with_group='groups').all()
if calc_results:
pks, uuids = map(list, zip(*calc_results))
entities_starting_set[NODE_ENTITY_NAME].update(uuids)
given_calculation_entry_ids.update(pks)
del calc_results, pks, uuids

for entity, entity_set in entities_starting_set.items():
entities_starting_set[entity] = list(entity_set)
Expand Down