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

Decouple endpoints from business logic #295

Open
4 tasks
jonathan-d-zhang opened this issue Jul 25, 2024 · 0 comments
Open
4 tasks

Decouple endpoints from business logic #295

jonathan-d-zhang opened this issue Jul 25, 2024 · 0 comments

Comments

@jonathan-d-zhang
Copy link
Contributor

jonathan-d-zhang commented Jul 25, 2024

We should extract as much business logic out of our endpoint functions as possible. This will give a number of benefits:

  • Easier testability. No longer have to make real requests to test business logic. Integration tests will be slimmed down substantially.
  • Easier management of database connection lifecycle. Currently, the issues with FastAPI's DI (see Investigate performance issues introduced by 9db3e05 #235) have led to very confusing handling of database connections and sessions. Leaving the connection handling entirely to the endpoint function will simplify our handling inside the business logic.
  • Unify SQL queries. Currently at least a few DB functions are repeated (looking up a package, for example). Extracting these queries to a separate module will let us deduplicate and isolate (SQL) security issues to one spot.

This effort will take a few PRs. My plan so far is to have each endpoint file refactoring take 1 PR each.

Extract business logic from these endpoints:

stats.py is missing because it's already in a good spot (and we want to nuke it soon).

The general idea is to extract sql queries to src/mainframe/database.py and deduplicate them + pull as much logic out of the endpoint functions as possible.

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

No branches or pull requests

1 participant