add: config db-timezone-enabled for optional querying of timezones
To avoid repeated querying of `pg_timezone_names` every time schema cache is reset, `Prefer: timezone` can be disabled by setting `db-timezone-enabled = false`. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
committed by
Steve Chavez
parent
bd5de884fa
commit
d6c338d588
@@ -94,6 +94,7 @@ data AppConfig = AppConfig
|
||||
, configDbSchemas :: NonEmpty Text
|
||||
, configDbConfig :: Bool
|
||||
, configDbPreConfig :: Maybe QualifiedIdentifier
|
||||
, configDbTimezoneEnabled :: Bool
|
||||
, configDbTxAllowOverride :: Bool
|
||||
, configDbTxRollbackAll :: Bool
|
||||
, configDbUri :: Text
|
||||
@@ -181,6 +182,7 @@ toText conf =
|
||||
,("db-schemas", q . T.intercalate "," . toList . configDbSchemas)
|
||||
,("db-config", T.toLower . show . configDbConfig)
|
||||
,("db-pre-config", q . maybe mempty dumpQi . configDbPreConfig)
|
||||
,("db-timezone-enabled", T.toLower . show . configDbTimezoneEnabled)
|
||||
,("db-tx-end", q . showTxEnd)
|
||||
,("db-uri", q . configDbUri)
|
||||
,("jwt-aud", q . fromMaybe mempty . configJwtAudience)
|
||||
@@ -290,6 +292,7 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
|
||||
<*> parseDbSchemas "db-schemas" "db-schema"
|
||||
<*> (fromMaybe True <$> optBool "db-config")
|
||||
<*> (fmap toQi <$> optString "db-pre-config")
|
||||
<*> (fromMaybe True <$> optBool "db-timezone-enabled")
|
||||
<*> parseTxEnd "db-tx-end" snd
|
||||
<*> parseTxEnd "db-tx-end" fst
|
||||
<*> (fromMaybe "postgresql://" <$> optString "db-uri")
|
||||
@@ -715,6 +718,9 @@ exampleConfigFile = S.unlines
|
||||
, "## The name of which database schema to expose to REST clients"
|
||||
, "db-schemas = \"public\""
|
||||
, ""
|
||||
, "## Enable quering pg_timezone_names from db"
|
||||
, "# db-timezone-enabled = true"
|
||||
, ""
|
||||
, "## How to terminate database transactions"
|
||||
, "## Possible values are:"
|
||||
, "## commit (default)"
|
||||
|
||||
@@ -56,6 +56,7 @@ dbSettingsNames =
|
||||
,"db_prepared_statements"
|
||||
,"db_root_spec"
|
||||
,"db_schemas"
|
||||
,"db_timezone_enabled"
|
||||
,"db_tx_end"
|
||||
,"db_hoisted_tx_settings"
|
||||
,"jwt_aud"
|
||||
|
||||
@@ -159,7 +159,9 @@ querySchemaCache conf@AppConfig{..} = do
|
||||
cRels <- SQL.statement mempty $ allComputedRels prepared
|
||||
reps <- SQL.statement conf $ dataRepresentations prepared
|
||||
mHdlers <- SQL.statement conf $ mediaHandlers prepared
|
||||
tzones <- SQL.statement mempty $ timezones prepared
|
||||
tzones <- if configDbTimezoneEnabled
|
||||
then SQL.statement mempty $ timezones prepared
|
||||
else pure S.empty
|
||||
_ <-
|
||||
let sleepCall = SQL.Statement "select pg_sleep($1 / 1000.0)" (param HE.int4) HD.noResult prepared in
|
||||
for_ configInternalSCQuerySleep (`SQL.statement` sleepCall) -- only used for testing
|
||||
@@ -1109,7 +1111,13 @@ decodeMediaHandlers =
|
||||
timezones :: Bool -> SQL.Statement () TimezoneNames
|
||||
timezones = SQL.Statement sql HE.noParams decodeTimezones
|
||||
where
|
||||
sql = "SELECT name FROM pg_timezone_names"
|
||||
sql = encodeUtf8 $ unlines
|
||||
-- This CTE wrapper is only added for clarifying the query under pg_stat_statements
|
||||
["WITH pgrst_timezones AS ("
|
||||
, " SELECT name FROM pg_timezone_names"
|
||||
, ")"
|
||||
, "SELECT * FROM pgrst_timezones"
|
||||
]
|
||||
decodeTimezones :: HD.Result TimezoneNames
|
||||
decodeTimezones = S.fromList <$> HD.rowList (column HD.text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user