-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add NodeGroup.grouping_node
#11613
#11614
base: dev/8.0.x
Are you sure you want to change the base?
Conversation
Node.nodegroup_root
#11613Node.grouping_node
#11613
arches/app/models/models.py
Outdated
@@ -907,15 +915,21 @@ def __init__(self, *args, **kwargs): | |||
def clean(self): | |||
if not self.alias: | |||
Graph.objects.get(pk=self.graph_id).create_node_alias(self) | |||
self.grouping_node_id = self.nodegroup_id |
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.
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.
Overall lgtm 🚀 ! One question in the body of code.
On a more meta note, if it's possible to add the Node
relation to NodeGroup
instead of this change and still power what you're trying to do I think there'd be an additional win gained there. There have been quite a few times I've needed to get the node from the nodegroup and end up running to the db again 💀
If that can't be accommodated, how do you feel about changing grouping_node
to nodegroup_node
? idk grouping_node
isn't really referenced elsewhere in code and IMO it's more descriptive to say what the thing actually is.
Thanks for taking a look. I'm going to pump the brakes for a couple days since I just got a few 👍 's on Slack for the idea of just factoring out a subquery into a queryset method. If you have to remember
I first had |
Cool cool! One thing re slack convo: And ++ for having the same thoughts about naming. Hopefully that makes it in 🤞 |
Yeah I think if we want other stuff from the node then it should go back to an FK, but I can definitely explore putting the column on the nodegroup. I'll give it some thought. |
I don't have a strong opinion on this. My preference is |
Also, |
I gave it some thought, and although it makes intuitive sense to put it on NodeGroup, I think there are some considerations going the other way:
This is actually my main motivation, and now there's a way to do that when fetching the data. On the other proposal (column on NodeGroup) you'd have to select_related() the grouping node when fetching data, so it's not like the developer gets a permission slip to not think about this ;) # Make sure to get grouping nodes before you need them
In [49]: with_grouping_nodes = NodeGroup.objects.filter(node__gt=0).prefetch_related('node_set__grouping_node').distinct()
In [50]: for ng in with_grouping_nodes:
...: print(ng.node_set.all()[0].grouping_node.alias) |
I agree with @chiatt. I think |
I would also say that from a "what makes the most sense" perspective (and not to throw a monkey wrench 🐵 🔧 into this discussion) that having this on the "Nodegroup" table makes the most sense. So, in that case you'd end with something like this Now pragmatically speaking this may not net us less db calls if that's what we're trying to achieve with this, but it does feel very natural. |
The system check in GraphModel.check() depends on the migrated model.
Node.grouping_node
#11613NodeGroup.root_node
#11613
Yeah, it makes good sense to move it. I can handle the missing safety with a Django system check. |
@chiatt ready for another look :-) |
If the test database is not set up, this check used to crash when running manage.py test.
198ca98
to
0f23a6c
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.
I'm OOO today but saw these interesting updates and wanted to stick my nose in 👃
operations = [ | ||
migrations.AddField( | ||
model_name="nodegroup", | ||
name="root_node", |
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.
I'd argue just node
here. root_node
is less clear and can have different connotations.
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.
Happy to hold this until everyone's happy with the name, but node
is the query name for a related item from node_set
, so I don't think we can overload that. I think we need to land on something.
arches/app/models/migrations/11613_nodegroup_root_node_constraints.py
Outdated
Show resolved
Hide resolved
NodeGroup.root_node
#11613NodeGroup.grouping_node
#11613
Types of changes
Description of Change
Before
From a node, to find the grouping node of that node's nodegroup, you would need to prefetch the sibling nodes and compare the results to the id of the nodegroup, or else just issue another Node.objects.get() to individually fetch the wanted node.
After
There is now a self-referencing foreign key to the other node that serves as the nodegroup root.Per discussion, there is now a OneToOneField on the NodeGroup model pointing to the root node for the nodegroup.
Example query:
Issues Solved
Closes #11613
Checklist
Ticket Background