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
Remove get_aiida_class
#2309
Remove get_aiida_class
#2309
Conversation
88547ac
to
71ce801
Compare
71ce801
to
4ddda92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few places with dead code, but good otherwise
4ddda92
to
0e74729
Compare
@@ -159,12 +162,12 @@ def __next__(self): | |||
def next(self): | |||
return next(self.generator) | |||
|
|||
return Iterator(self._dbmodel.dbnodes.all()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to replace this with self._dbmodel.dbnodes.all().iterator()
for lazy loading also while looping with iter and next, see
see also here http://blog.etianen.com/blog/2013/06/08/django-querysets/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but we can't call count() on the iterator so I only use the iterator in the actually iteration code.
aiida/orm/groups.py
Outdated
@@ -269,7 +273,7 @@ def nodes(self): | |||
the respective AiiDA subclasses of Node, and also allows to ask for | |||
the number of nodes in the group using len(). | |||
""" | |||
return self._backend_entity.nodes | |||
return map(convert.get_orm_entity, self._backend_entity.nodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a custom Iterator class as it is done in the Backend classes to have len pipe through the .count() method of the ORM, for efficiency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
aiida/cmdline/commands/cmd_group.py
Outdated
@@ -79,7 +79,7 @@ def group_delete(group, force): | |||
group_pk = group.pk | |||
group_name = group.name | |||
|
|||
num_nodes = len(group.nodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go back to len(group.nodes)
once the suggested fix for len is in place, for efficiency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
86ef75d
to
9693d45
Compare
Added convertors to go from a DbModel BackendEntity and from BackendEntity to OrmEntity.
Replaced all instances with either `get_backend_entity` or `get_orm_entity` (as appropriate). Also changed backend group to be independent of the ORM. Because the iterator was getting the ORM class and returning that, which required it to access up to the ORM level. Now it just returns backend entities which are in turn converted to ORM entities by the `orm.Group`. This also means you can't call `len(group.nodes)` because this is not allowed for iterators but the same can be achieved with `len(list(group.nodes))`
61709bb
to
1a9c869
Compare
Fixes #2237
This is part of the procedure that @szoupanos is leading to convert to automatically generated dummy models for the
QueryBuilder
Replaced all instances with either get_backend_entity or get_orm_entity
(as appropriate).
Also changed backend group to be independent of the ORM. Because the
iterator was getting the orm class and returning that (which required it
to access up to the ORM level). Now it just returns backend entities
which are in turn converted to ORM entities by the orm.Group. This also
means you can't call len(group.nodes) because this is not allowed for
iterators but the same can be achieved with
len(list(group.nodes))
.Removal of
get_aiida_class
from QueryBuilder and addition ofDbModel-to-BackendEntity
andBackendEntity-to-OrmEntity
convertors.