fix: HEAD unnecessarily executing aggregates
This commit is contained in:
committed by
Steve Chavez
parent
905fcb05cc
commit
e332f038ef
@@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #2821, Fix OPTIONS not accepting all available media types - @steve-chavez
|
- #2821, Fix OPTIONS not accepting all available media types - @steve-chavez
|
||||||
- #2834, Fix compilation on Ubuntu by being compatible with GHC 9.0.2 - @steve-chavez
|
- #2834, Fix compilation on Ubuntu by being compatible with GHC 9.0.2 - @steve-chavez
|
||||||
- #2840, Fix `Prefer: missing=default` with DOMAIN default values - @steve-chavez
|
- #2840, Fix `Prefer: missing=default` with DOMAIN default values - @steve-chavez
|
||||||
|
- #2849, Fix HEAD unnecessarily executing aggregates - @steve-chavez
|
||||||
|
|
||||||
## [11.1.0] - 2023-06-07
|
## [11.1.0] - 2023-06-07
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ module PostgREST.MediaType
|
|||||||
, toContentType
|
, toContentType
|
||||||
, toMime
|
, toMime
|
||||||
, decodeMediaType
|
, decodeMediaType
|
||||||
, getMediaType
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
@@ -143,8 +142,3 @@ decodeMediaType mt =
|
|||||||
[PlanSettings | inOpts "settings"] ++
|
[PlanSettings | inOpts "settings"] ++
|
||||||
[PlanBuffers | inOpts "buffers" ] ++
|
[PlanBuffers | inOpts "buffers" ] ++
|
||||||
[PlanWAL | inOpts "wal" ]
|
[PlanWAL | inOpts "wal" ]
|
||||||
|
|
||||||
getMediaType :: MediaType -> MediaType
|
|
||||||
getMediaType mt = case mt of
|
|
||||||
MTPlan mType _ _ -> mType
|
|
||||||
other -> other
|
|
||||||
|
|||||||
+15
-9
@@ -112,14 +112,14 @@ wrappedReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest
|
|||||||
wrappedReadPlan identifier conf sCache apiRequest = do
|
wrappedReadPlan identifier conf sCache apiRequest = do
|
||||||
rPlan <- readPlan identifier conf sCache apiRequest
|
rPlan <- readPlan identifier conf sCache apiRequest
|
||||||
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) Nothing rPlan
|
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) Nothing rPlan
|
||||||
return $ WrappedReadPlan rPlan SQL.Read $ mediaToAggregate (iAcceptMediaType apiRequest) binField Nothing
|
return $ WrappedReadPlan rPlan SQL.Read $ mediaToAggregate (iAcceptMediaType apiRequest) binField apiRequest
|
||||||
|
|
||||||
mutateReadPlan :: Mutation -> ApiRequest -> QualifiedIdentifier -> AppConfig -> SchemaCache -> Either Error MutateReadPlan
|
mutateReadPlan :: Mutation -> ApiRequest -> QualifiedIdentifier -> AppConfig -> SchemaCache -> Either Error MutateReadPlan
|
||||||
mutateReadPlan mutation apiRequest@ApiRequest{iPreferences=Preferences{preferRepresentation}} identifier conf sCache = do
|
mutateReadPlan mutation apiRequest identifier conf sCache = do
|
||||||
rPlan <- readPlan identifier conf sCache apiRequest
|
rPlan <- readPlan identifier conf sCache apiRequest
|
||||||
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) Nothing rPlan
|
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) Nothing rPlan
|
||||||
mPlan <- mutatePlan mutation identifier apiRequest sCache rPlan
|
mPlan <- mutatePlan mutation identifier apiRequest sCache rPlan
|
||||||
return $ MutateReadPlan rPlan mPlan SQL.Write $ mediaToAggregate (iAcceptMediaType apiRequest) binField (Just preferRepresentation)
|
return $ MutateReadPlan rPlan mPlan SQL.Write $ mediaToAggregate (iAcceptMediaType apiRequest) binField apiRequest
|
||||||
|
|
||||||
callReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest -> InvokeMethod -> Either Error CallReadPlan
|
callReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest -> InvokeMethod -> Either Error CallReadPlan
|
||||||
callReadPlan identifier conf sCache apiRequest invMethod = do
|
callReadPlan identifier conf sCache apiRequest invMethod = do
|
||||||
@@ -144,7 +144,7 @@ callReadPlan identifier conf sCache apiRequest invMethod = do
|
|||||||
(InvPost, Routine.Volatile) -> SQL.Write
|
(InvPost, Routine.Volatile) -> SQL.Write
|
||||||
cPlan = callPlan proc apiRequest paramKeys args rPlan
|
cPlan = callPlan proc apiRequest paramKeys args rPlan
|
||||||
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) (Just proc) rPlan
|
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) (Just proc) rPlan
|
||||||
return $ CallReadPlan rPlan cPlan txMode proc $ mediaToAggregate (iAcceptMediaType apiRequest) binField Nothing
|
return $ CallReadPlan rPlan cPlan txMode proc $ mediaToAggregate (iAcceptMediaType apiRequest) binField apiRequest
|
||||||
where
|
where
|
||||||
Preferences{..} = iPreferences apiRequest
|
Preferences{..} = iPreferences apiRequest
|
||||||
qsParams' = QueryParams.qsParams (iQueryParams apiRequest)
|
qsParams' = QueryParams.qsParams (iQueryParams apiRequest)
|
||||||
@@ -839,10 +839,10 @@ binaryField AppConfig{configRawMediaTypes} acceptMediaType proc rpTree
|
|||||||
fstFieldName (Node ReadPlan{select=[(CoercibleField{cfName=fld, cfJsonPath=[]}, _, _)]} []) = Just fld
|
fstFieldName (Node ReadPlan{select=[(CoercibleField{cfName=fld, cfJsonPath=[]}, _, _)]} []) = Just fld
|
||||||
fstFieldName _ = Nothing
|
fstFieldName _ = Nothing
|
||||||
|
|
||||||
mediaToAggregate :: MediaType -> Maybe FieldName -> Maybe PreferRepresentation -> ResultAggregate
|
|
||||||
mediaToAggregate mt binField rep =
|
mediaToAggregate :: MediaType -> Maybe FieldName -> ApiRequest -> ResultAggregate
|
||||||
if rep == Just HeadersOnly || rep == Just None
|
mediaToAggregate mt binField apiReq@ApiRequest{iAction=act, iPreferences=Preferences{preferRepresentation=rep}} =
|
||||||
then NoAgg
|
if noAgg then NoAgg
|
||||||
else case mt of
|
else case mt of
|
||||||
MTApplicationJSON -> BuiltinAggJson
|
MTApplicationJSON -> BuiltinAggJson
|
||||||
MTSingularJSON -> BuiltinAggSingleJson
|
MTSingularJSON -> BuiltinAggSingleJson
|
||||||
@@ -861,4 +861,10 @@ mediaToAggregate mt binField rep =
|
|||||||
-- Doing `Accept: application/vnd.pgrst.plan; for="application/vnd.pgrst.plan"` doesn't make sense, so we just empty the body.
|
-- Doing `Accept: application/vnd.pgrst.plan; for="application/vnd.pgrst.plan"` doesn't make sense, so we just empty the body.
|
||||||
-- TODO: fail instead to be more strict
|
-- TODO: fail instead to be more strict
|
||||||
MTPlan (MTPlan{}) _ _ -> NoAgg
|
MTPlan (MTPlan{}) _ _ -> NoAgg
|
||||||
MTPlan media _ _ -> mediaToAggregate media binField rep
|
MTPlan media _ _ -> mediaToAggregate media binField apiReq
|
||||||
|
where
|
||||||
|
noAgg = case act of
|
||||||
|
ActionMutate _ -> rep == HeadersOnly || rep == None
|
||||||
|
ActionRead _isHead -> _isHead -- no need for an aggregate on HEAD https://github.com/PostgREST/postgrest/issues/2849
|
||||||
|
ActionInvoke invMethod -> invMethod == InvHead
|
||||||
|
_ -> False
|
||||||
|
|||||||
Reference in New Issue
Block a user