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

Optimization Hints #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Optimization Hints #5

wants to merge 7 commits into from

Conversation

FrownyFace
Copy link

@FrownyFace FrownyFace commented Jun 12, 2019

usage (inside graphql_schema/clinical_notes.py

@resolver_hints(select_related=["locked_by"])
def resolve_lock(self, _info):
  • black formatting

Copy link

@cassiemeharry cassiemeharry left a comment

Choose a reason for hiding this comment

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

Since you're apparently applying Black to the project, could you add/update the pyproject.toml file so the files stay formatted?

class OptimizationHints(object):
def __init__(self, model_field=None, select_related=None, prefetch_related=None, only=None):
self.model_field = model_field
self.prefetch_related = prefetch_related if prefetch_related else []

Choose a reason for hiding this comment

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

These should be set objects.

self.prefetch_related = set(prefetch_related) if prefetch_related else set()
self.select_related = set(select_related) if select_related else set()
self.only = set(only) if only else set()


optimization_hints = getattr(field_def.resolver, "optimization_hints", None)
if optimization_hints:
[

Choose a reason for hiding this comment

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

Using a list comprehension only for its side effects is considered bad style. I see that it's doing this a few lines up as well, but that should be fixed.

If you work with set objects, you can skip the explicit loop entirely and express the intent of merging in the new entries directly:

select_related = sorted(set(select_related) | optimization_hints.select_related)

The sorted() call is only necessary because the rest of the library doesn't pass those fields around as sets like it should.

for x in optimization_hints.select_related
if x not in select_related
]
[

Choose a reason for hiding this comment

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

Same for prefetch_related here as well.

graphene_django_extras/utils.py Show resolved Hide resolved
@AlecRosenbaum
Copy link

I haven't actually looked at the code here yet, but I think on forked repos we should probably follow the model of having master always stay up to date with upstream's master, then use a custom drchrono branch or something like that for changes that we've made to our fork.

Then this PR would probably be directed into a drchrono branch

Once changes for nick's feedback are in, I'll take a look at the code as well

@cassiemeharry
Copy link

You know, that's actually a good point. To keep this relatively up to date, we should avoid doing extra formatting changes if we can avoid it. Otherwise, we're going to forever run into merge conflicts when we merge the upstream version into our own.

@FrownyFace Can you please undo the Black formatting, and pare this PR down to the core changes?

@AlecRosenbaum
Copy link

@nickmeharry I'm pretty sure the project already uses black, I think they just do it with different line length settings. I think we just have to make sure black is actually respecting this project's settings

@cassiemeharry
Copy link

Ok. My point stands though, this diff is too big to maintain in a fork if we want any hope of keeping things up to date. I guess figure out the line length this project uses and format it that way, so only meaningful changes are present here?

@AlecRosenbaum
Copy link

@nickmeharry I agree with you. This project's pyproject.toml specifies 88, I think the formatter just didn't pick up the right pyproject file

@FrownyFace
Copy link
Author

un-formatted + nick changes incorporated @AlecRosenbaum

@AlecRosenbaum
Copy link

Who is taking over ownership of this change/project?

@VKuber Any thoughts on who will be taking over DW-11248?

@MicGong
Copy link

MicGong commented Nov 6, 2019

This might be resolved with graphene-django 2.4.0 release.

@AlecRosenbaum
Copy link

Could you remove my review request from this PR? I don't have edit access anymore and this has been sitting in my review requests for quite some time now.

I'm not sure who has access to do this still, maybe @cassiemeharry?

@MicGong MicGong removed the request for review from AlecRosenbaum July 15, 2020 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants