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

[batch] Avoid computing billing project cost when not needed #13210

Merged
merged 3 commits into from
Jun 26, 2023

Conversation

jigold
Copy link
Contributor

@jigold jigold commented Jun 23, 2023

No description provided.

Copy link
Contributor

@daniel-goldstein daniel-goldstein left a comment

Choose a reason for hiding this comment

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

I think this is getting a little hard to follow with all these conditionals. Can we just make separate functions for these separate queries? I think it's easier to think of what the two pages need in isolation from one another.

args.append(user)

if billing_project:
where_conditions.append('billing_projects.name_cs = %s')
conditions.append('billing_projects.name_cs = %s')
args.append(billing_project)
Copy link
Contributor

Choose a reason for hiding this comment

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

While this deduplicates some code, it also fragments the query, and I can't really understand what this function is doing unless I look at where it's used (where does this users json come from?). I think it's worth sacrificing the duplication to put this code in place in the functions that call this one instead of having this function.

else:
record['users'] = json.loads(record['users'])
return record
billing_projects = [users_record_to_dict(record) async for record in db.execute_and_fetchall(sql, tuple(args))]
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't new in this PR so feel free to take or leave this critique, but I personally find functions that both mutate inputs hard to reason about, as I would expect a void function to mutate and a function with a return value to leave its inputs alone. I might prefer to write this the following way:

billing_projects = []
async for record in db.execute_and_fetchall(sql, tuple(args)):
    record['users'] = json.loads(record['users']) if record['users'] is not None else []
    billing_projects.append(record)    

@danking danking merged commit 7bd4af2 into hail-is:main Jun 26, 2023
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.

3 participants