Skip to content

Commit 4819520

Browse files
taimoorzaeemsteve-chavez
authored andcommitted
refactor: decouple module SchemaCache and ApiRequest
1 parent 359e5fb commit 4819520

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/PostgREST/ApiRequest.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Description : PostgREST functions to translate HTTP request to a domain type cal
44
-}
55
{-# LANGUAGE LambdaCase #-}
66
{-# LANGUAGE NamedFieldPuns #-}
7-
-- TODO: This module shouldn't depend on SchemaCache
87
module PostgREST.ApiRequest
98
( ApiRequest(..)
109
, InvokeMethod(..)
@@ -46,14 +45,14 @@ import Web.Cookie (parseCookies)
4645
import PostgREST.ApiRequest.QueryParams (QueryParams (..))
4746
import PostgREST.Config (AppConfig (..),
4847
OpenAPIMode (..))
48+
import PostgREST.Config.Database (TimezoneNames)
4949
import PostgREST.Error (ApiRequestError (..),
5050
RangeError (..))
5151
import PostgREST.MediaType (MediaType (..))
5252
import PostgREST.RangeQuery (NonnegRange, allRange,
5353
convertToLimitZeroRange,
5454
hasLimitZero,
5555
rangeRequested)
56-
import PostgREST.SchemaCache (SchemaCache (..))
5756
import PostgREST.SchemaCache.Identifiers (FieldName,
5857
QualifiedIdentifier (..),
5958
Schema)
@@ -128,8 +127,10 @@ data ApiRequest = ApiRequest {
128127
}
129128

130129
-- | Examines HTTP request and translates it into user intent.
131-
userApiRequest :: AppConfig -> Request -> RequestBody -> SchemaCache -> Either ApiRequestError ApiRequest
132-
userApiRequest conf req reqBody sCache = do
130+
--
131+
-- TimezoneNames are used by Prefer: timezone
132+
userApiRequest :: AppConfig -> Request -> RequestBody -> TimezoneNames -> Either ApiRequestError ApiRequest
133+
userApiRequest conf req reqBody timezones = do
133134
resource <- getResource conf $ pathInfo req
134135
(schema, negotiatedByProfile) <- getSchema conf hdrs method
135136
act <- getAction resource schema method
@@ -141,7 +142,7 @@ userApiRequest conf req reqBody sCache = do
141142
, iRange = ranges
142143
, iTopLevelRange = topLevelRange
143144
, iPayload = payload
144-
, iPreferences = Preferences.fromHeaders (configDbTxAllowOverride conf) (dbTimezones sCache) hdrs
145+
, iPreferences = Preferences.fromHeaders (configDbTxAllowOverride conf) timezones hdrs
145146
, iQueryParams = qPrms
146147
, iColumns = columns
147148
, iHeaders = iHdrs

src/PostgREST/App.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache pgVer authResult@
144144
body <- lift $ Wai.strictRequestBody req
145145

146146
let jwtTime = if configServerTimingEnabled then Auth.getJwtDur req else Nothing
147+
timezones = dbTimezones sCache
147148

148-
(parseTime, apiReq@ApiRequest{..}) <- withTiming $ liftEither . mapLeft Error.ApiRequestError $ ApiRequest.userApiRequest conf req body sCache
149+
(parseTime, apiReq@ApiRequest{..}) <- withTiming $ liftEither . mapLeft Error.ApiRequestError $ ApiRequest.userApiRequest conf req body timezones
149150
(planTime, plan) <- withTiming $ liftEither $ Plan.actionPlan iAction conf apiReq sCache
150151

151152
let query = Query.query conf authResult apiReq plan sCache pgVer

0 commit comments

Comments
 (0)