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

[dev] Refactoring roadmap #1804

Open
13 of 27 tasks
monacoremo opened this issue Apr 11, 2021 · 10 comments
Open
13 of 27 tasks

[dev] Refactoring roadmap #1804

monacoremo opened this issue Apr 11, 2021 · 10 comments
Labels
hygiene cleanup or refactoring

Comments

@monacoremo
Copy link
Member

monacoremo commented Apr 11, 2021

With #1793, we've started the process of streamlining the codebase. This is a purely internal concern that will yield no additional features. It will, however:

  • ease maintenance
  • help with the onboarding of new contributors
  • enable quicker implementation of new features
  • further increase confidence on correctness

Next steps include (in no particular order and to be completed - please feel free to edit)

Other:

  • Add a postgrest-install-git-hooks script
@steve-chavez
Copy link
Member

Putting another pending refactor here.

We had an issue where Content-Type was being considered for GET - invalid since it has no body. This happened mostly because a typing deficiency(still present). More details at #2168 (comment).

@steve-chavez
Copy link
Member

unsafeHead went away on #2254

@steve-chavez
Copy link
Member

steve-chavez commented Oct 4, 2022

Request: purely parse request, at most taking config into account. `parseRequest :: Wai.Request -> Either RequestError Request

Plan: Use db structure to validate and plan the request, including embeds. plan :: DbStructure -> Request -> Either PlanError QueryPlan

To do the above, ApiRequest should remove its dependency on DbStructure - which is needed by the variadic logic introduced on #1603.

if not $ pdHasVariadic proc then -- if proc has no variadic param, save steps and directly convert to json

After that findProc and others can be moved to Plan.hs and ApiRequest will be much cleaner.

I tried to do this on #2496 but it turned out difficult bc I'm not familiar with the variadic logic. @wolfgangwalther Would be great if you could help with that.


Ideally the proc logic shouldn't be where the body processing is done. Like on MTUrlEncoded here

(MTUrlEncoded, ActionInvoke InvPost) -> targetToJsonRpcParams (rightToMaybe target) $ (T.decodeUtf8 *** T.decodeUtf8) <$> parseSimpleQuery (LBS.toStrict reqBody)

That logic should happen after, on the Plan module.

@wolfgangwalther
Copy link
Member

The challenge is, that ApiRequest does pass on URL parameters as iPayload, i.e. payload is either the request body or a json produced from the params. ApiRequest needs to split this up and have the params as just a [(Text, Text)] list. Then, Plan can do the list -> map later, taking the ProcDescription into account.

@steve-chavez
Copy link
Member

steve-chavez commented Feb 7, 2023

I've been thinking about how we transform requests, and seeing the The Internals of PostgreSQL query processing chapter here:

1. Parser
The parser generates a parse tree from an SQL statement in plain text.

2. Analyzer/Analyser
The analyzer/analyser carries out a semantic analysis of a parse tree and generates a query tree.

3. Rewriter
The rewriter transforms a query tree using the rules stored in the rule system if such rules exist.

4. Planner
The planner generates the plan tree that can most effectively be executed from the query tree.

5. Executor
The executor executes the query via accessing the tables and indexes in the order that was created by the plan tree.

It seems:

  • Our ApiRequest is the Parser
  • Analyzer is really what we call Plan now.
  • The Rewriter concept could be used to further split our Plan module, which is getting big. For example computed relationships could be thought of as a "rewrite". Data Representations #2523 seems like a rewrite too.
  • We don't have a Planner per se. This is a further optimization that perhaps could be used to reduce generated prepared statements, e.g. select=id,name could generate the same query as select=name,id. Not sure about this.
    • Maybe we could have sort of a "prepared request" akin to pg "prepared statement".
  • Executor doesn't make sense for us.

@steve-chavez

This comment was marked as outdated.

@steve-chavez
Copy link
Member

steve-chavez commented Mar 6, 2023

Continuing the above idea. Our App.hs module can be equated to the TrafficCop in PostgreSQL https://wiki.postgresql.org/wiki/Backend_flowchart#Main_Query_Flow

These ideas can be used to structure our modules and to improve the ARCHITECTURE.md.

@steve-chavez steve-chavez added hygiene cleanup or refactoring and removed dev labels Jun 5, 2023
@steve-chavez
Copy link
Member

There are still some pending refactors but overall the structure now is in line with the original comment. Will unpin this issue as it's not urgent anymore. We can now grow the codebase in a more maintainable manner.

@steve-chavez steve-chavez unpinned this issue Jun 8, 2023
@dbaynard
Copy link
Contributor

dbaynard commented Jun 8, 2023

Congratulations — great job!

  • help with the onboarding of new contributors

As a (current) non-contributer I'm willing to help test this.

@wolfgangwalther
Copy link
Member

We should consider moving away from protolude, because it's essentially unsupported upstream: protolude/protolude#150 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hygiene cleanup or refactoring
Development

No branches or pull requests

4 participants