Skip to content

API server code health pass - misc. refactors #1059

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

Merged
merged 6 commits into from
Dec 22, 2022

Conversation

rzats
Copy link
Contributor

@rzats rzats commented Dec 22, 2022

Partially addresses #998.

Prerequisites:

  • Unless it is a documentation hotfix it should be merged against the dev branch
  • Branch is up-to-date with the branch to be merged with, i.e. dev
  • Build is successful
  • Code is cleaned up and formatted

Summary

Fixes a set of issues in the server code as described here.

  • Splits _handle_lag_issues_as_of() into three separate methods, removes no-op usage.
  • Reworks set_order() method to remove unneeded sorting complexity, renames to set_sort_order.
  • Removes unused get_related_signals() method.
  • Removes _db.py, moves the SQLAlchemy engine definition from it to _common.py.
  • Expands usage of the IntValues type alias.

Copy link
Collaborator

@melange396 melange396 left a comment

Choose a reason for hiding this comment

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

if we are gonna push the IntRange thing through, we might as well include it in other similar type variations... so like replace Union[str, Tuple[int, int], int] with Union[str, IntRange] too.

kw_order = [f"{self.alias}.{k} {to_asc(v)}" for k, v in kwargs.items()]
self.order = args_order + kw_order
return self
self.order = [f"{self.alias}.{k} ASC" for k in args]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.order = [f"{self.alias}.{k} ASC" for k in args]
self.order = [f"{self.alias}.{k} ASC" for k in args]
return self

Copy link
Contributor Author

@rzats rzats Dec 22, 2022

Choose a reason for hiding this comment

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

This is actually one of the refactors I wanted to apply to query.py - the return self is intended to be used for method cascading:

q.apply_issues_filter().apply_lag_filter().apply_as_of_filter()

but it is not used that way anywhere in the codebase, so the statements serve no purpose. Do we still need to keep the return self for some other reason? (Or perhaps start using that style of cascading after all?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can allow method cascading without requiring it. the rest of the methods of QueryBuilder do return self, and its best to keep that consistent especially in case someone does eventually choose to write something with cascading. its also not bad form to return self on mutator methods from a functional programming perspective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! I actually wanted to remove return self from those other methods too but you make a great point about the functional programming angle.

@rzats rzats requested a review from melange396 December 22, 2022 22:31
@rzats rzats merged commit 44ff896 into dev Dec 22, 2022
@rzats rzats deleted the rzatserkovnyi/code-health-misc branch December 22, 2022 23:47
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.

2 participants