Skip to content

refactor: App control flow refactoring#4969

Draft
mkleczek wants to merge 1 commit into
PostgREST:mainfrom
mkleczek:refactor/app-control-flow
Draft

refactor: App control flow refactoring#4969
mkleczek wants to merge 1 commit into
PostgREST:mainfrom
mkleczek:refactor/app-control-flow

Conversation

@mkleczek
Copy link
Copy Markdown
Collaborator

@mkleczek mkleczek commented Jun 1, 2026

App control flow refactoring

  1. Handling of NoDb ActionPlan in database related code.
    Make MainTx.mainTx and Query.mainQuery receive DbPlan instead of ActionPlan so that they do not have to handle unrelated NoDb cases.
    Removed "NoDbResult" constructor from "DbResult" datatype and factored out noDbActionResponse from actionResponse to clearly separate "DbResult" and "InfoPlan" handling.

  2. Server timing is now handled using WriterT monad so that it does not pollute the control flow.
    Timings are accumulated in [(ByteString, Double)] list and then, if the list is not empty, passed to Performance.serverTimingHeader as NonEmpty (ByteString, Double)

  3. Moved authentication back to App.postgrestResponse so that all steps that require timing are encapsulated. In refactor: remove auth and logging middleware #4884 it was moved level up the call chain which, while achieving the goal of removing auth middleware, made the control flow complicated and difficult to follow. Thanks to introduction of WriterT based handling of auth role in refactor: simplify control flow in App.postgrest #4968, it is now possible to return to have all request handling pipeline steps in App.postgrestResponse. That also allows to make withTiming local binding again.

This PR is a follow up on #4968.

@mkleczek mkleczek force-pushed the refactor/app-control-flow branch 21 times, most recently from 9d4b293 to 9350465 Compare June 2, 2026 05:37
refactor: App control flow refactoring

1. Handling of NoDb ActionPlan in database related code.
Make MainTx.mainTx and Query.mainQuery receive DbPlan instead of ActionPlan so that they do not have to handle unrelated NoDb cases.
Removed "NoDbResult" constructor from "DbResult" datatype and factored out noDbActionResponse from actionResponse to clearly separate "DbResult" and "InfoPlan" handling.

2. Server timing is now handled using WriterT monad so that it does not pollute the control flow.
Timings are accumulated in [(ByteString, Double)] list and then, if the list is not empty, passed to Performance.serverTimingHeader as (NonEmpty (ByteString, Double)

3. postgrestResponse now returns PgrstResponse and Wai.Response creation is moved to postgrest. The reason is that Wai.Response requires timings but timing gathering is split between postgrest and postgrestResponse functions. That made the code weird because postgrest must have passed JWT timing to postgrestResponse.
Moving Wai.Response creation level up simplifies it.
@mkleczek mkleczek force-pushed the refactor/app-control-flow branch from 9350465 to 42da614 Compare June 2, 2026 07:13
@wolfgangwalther
Copy link
Copy Markdown
Member

This PR is a follow up on #4969 and is structured into multiple commits that introduce smaller changes.

I'm confused: This is a self-reference and there is only one commit in here.

@mkleczek
Copy link
Copy Markdown
Collaborator Author

mkleczek commented Jun 6, 2026

I'm confused: This is a self-reference and there is only one commit in here.

Yes, sorry - during reworking of this PR the description got outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants