Skip to content

Commit

Permalink
refactor: Simplify funcsSqlQuery
Browse files Browse the repository at this point in the history
This allows to re-use ANY($$1) in the next commit.
  • Loading branch information
wolfgangwalther committed Jul 9, 2024
1 parent 735e1ed commit f31848f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/PostgREST/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ actionQuery (MaybeDb plan@InspectPlan{ipSchema=tSchema}) AppConfig{..} _ _ sCach
tableAccess <- SQL.statement [tSchema] (SchemaCache.accessibleTables configDbPreparedStatements)
MaybeDbResult plan . Just <$> ((,,)
(HM.filterWithKey (\qi _ -> S.member qi tableAccess) $ SchemaCache.dbTables sCache)
<$> SQL.statement (tSchema, configDbHoistedTxSettings) (SchemaCache.accessibleFuncs configDbPreparedStatements)
<$> SQL.statement ([tSchema], configDbHoistedTxSettings) (SchemaCache.accessibleFuncs configDbPreparedStatements)
<*> SQL.statement tSchema (SchemaCache.schemaDescription configDbPreparedStatements))
OAIgnorePriv ->
MaybeDbResult plan . Just <$> ((,,)
Expand Down
13 changes: 6 additions & 7 deletions src/PostgREST/SchemaCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,19 @@ dataRepresentations = SQL.Statement sql mempty decodeRepresentations
|]

allFunctions :: Bool -> SQL.Statement AppConfig RoutineMap
allFunctions = SQL.Statement sql params decodeFuncs
allFunctions = SQL.Statement funcsSqlQuery params decodeFuncs
where
params =
(toList . configDbSchemas >$< arrayParam HE.text) <>
(configDbHoistedTxSettings >$< arrayParam HE.text)
sql =
funcsSqlQuery <> " AND pn.nspname = ANY($1)"

accessibleFuncs :: Bool -> SQL.Statement (Schema, [Text]) RoutineMap
accessibleFuncs :: Bool -> SQL.Statement ([Schema], [Text]) RoutineMap
accessibleFuncs = SQL.Statement sql params decodeFuncs
where
params =
(fst >$< param HE.text) <>
(fst >$< arrayParam HE.text) <>
(snd >$< arrayParam HE.text)
sql = funcsSqlQuery <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')"
sql = funcsSqlQuery <> " AND has_function_privilege(p.oid, 'execute')"

funcsSqlQuery :: SqlQuery
funcsSqlQuery = encodeUtf8 [trimming|
Expand Down Expand Up @@ -465,7 +463,8 @@ funcsSqlQuery = encodeUtf8 [trimming|
WHERE setting ~ ANY($$2)
) func_settings ON TRUE
WHERE t.oid <> 'trigger'::regtype AND COALESCE(a.callable, true)
AND prokind = 'f'|]
AND prokind = 'f'
AND pn.nspname = ANY($$1) |]

schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text)
schemaDescription =
Expand Down

0 comments on commit f31848f

Please sign in to comment.