Skip to content

Commit d33a054

Browse files
committed
refactor(remove): schema cache load delay config
Remove internal schema cache load and relationship load sleep settings plus the delay wrappers they enabled. Drop IO tests that depended on the removed settings.
1 parent 86d6ed1 commit d33a054

5 files changed

Lines changed: 4 additions & 89 deletions

File tree

src/PostgREST/Config.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ data AppConfig = AppConfig
127127
, configRoleSettings :: RoleSettings
128128
, configRoleIsoLvl :: RoleIsolationLvl
129129
, configInternalSCQuerySleep :: Maybe Int32
130-
, configInternalSCLoadSleep :: Maybe Int32
131-
, configInternalSCRelLoadSleep :: Maybe Int32
132130
}
133131

134132
data LogLevel = LogCrit | LogError | LogWarn | LogInfo | LogDebug
@@ -328,8 +326,6 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
328326
<*> pure roleSettings
329327
<*> pure roleIsolationLvl
330328
<*> optInt "internal-schema-cache-query-sleep"
331-
<*> optInt "internal-schema-cache-load-sleep"
332-
<*> optInt "internal-schema-cache-relationship-load-sleep"
333329
where
334330
parseErrorVerbosity :: C.Key -> C.Parser C.Config Verbosity
335331
parseErrorVerbosity k =

src/PostgREST/SchemaCache.hs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ import PostgREST.SchemaCache.Table (Column (..), ColumnMap,
7272

7373
import qualified PostgREST.MediaType as MediaType
7474

75-
import Control.Arrow ((&&&))
76-
import qualified Data.FuzzySet as Fuzzy
75+
import Control.Arrow ((&&&))
76+
import qualified Data.FuzzySet as Fuzzy
7777
import Protolude
78-
import System.IO.Unsafe (unsafePerformIO)
7978

8079
type TablesFuzzyIndex = HM.HashMap Schema Fuzzy.FuzzySet
8180

@@ -180,11 +179,9 @@ querySchemaCache conf@AppConfig{..} = do
180179
let tabsWViewsPks = addViewPrimaryKeys tabs keyDeps
181180
rels = addInverseRels $ addM2MRels tabsWViewsPks $ addViewM2OAndO2ORels keyDeps m2oRels
182181

183-
-- Add delay in loading schema cache when internal-schema-cache-load-sleep config is set
184-
return $ delayEval configInternalSCLoadSleep $ removeInternal schemas $ SchemaCache {
182+
return $ removeInternal schemas $ SchemaCache {
185183
dbTables = tabsWViewsPks
186-
-- Add delay in loading relationships when internal-schema-cache-relationship-load-sleep config is set
187-
, dbRelationships = delayEval configInternalSCRelLoadSleep $ getOverrideRelationshipsMap rels cRels
184+
, dbRelationships = getOverrideRelationshipsMap rels cRels
188185
, dbRoutines = funcs
189186
, dbRepresentations = reps
190187
, dbMediaHandlers = HM.union mHdlers initialMediaHandlers -- the custom handlers will override the initial ones
@@ -198,7 +195,6 @@ querySchemaCache conf@AppConfig{..} = do
198195
}
199196
where
200197
schemas = toList configDbSchemas
201-
delayEval confDelay result = maybe result (unsafePerformIO . (($> result) . (threadDelay . (1000 *) . fromIntegral))) confDelay
202198
isLogDebug = configLogLevel == LogDebug
203199
sqlTimedStmt = sqlTimedStatement isLogDebug
204200

test/io/test_io.py

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,31 +1447,6 @@ def test_schema_cache_query_sleep_logs(defaultenv):
14471447
assert 1000 < observed_ms < 2000
14481448

14491449

1450-
def test_schema_cache_load_sleep_logs(defaultenv):
1451-
"""Schema cache load sleep should be reflected in the logged load duration."""
1452-
1453-
env = {
1454-
**defaultenv,
1455-
"PGRST_INTERNAL_SCHEMA_CACHE_LOAD_SLEEP": "1000",
1456-
}
1457-
log_pattern = re.compile(r"Schema cache loaded in ([\d.]+) milliseconds")
1458-
1459-
with run(env=env, wait_max_seconds=3, no_startup_stdout=False) as postgrest:
1460-
observed_ms = None
1461-
collected = []
1462-
1463-
lines = postgrest.read_stdout(nlines=10)
1464-
collected.extend(lines)
1465-
for line in lines:
1466-
match = log_pattern.search(line)
1467-
if match:
1468-
observed_ms = float(match.group(1))
1469-
break
1470-
1471-
assert observed_ms is not None
1472-
assert 1000 < observed_ms < 2000
1473-
1474-
14751450
@pytest.mark.parametrize("timezone_enabled", ["true", "false"])
14761451
@pytest.mark.parametrize("level", ["crit", "error", "warn", "info", "debug"])
14771452
def test_schema_cache_query_timings_log(level, timezone_enabled, defaultenv):
@@ -2109,54 +2084,6 @@ def test_db_pre_config_with_pg_reserved_words(defaultenv):
21092084
)
21102085

21112086

2112-
def test_requests_with_resource_embedding_wait_for_schema_cache_reload(defaultenv):
2113-
"requests that use the schema cache with resource embedding wait long for the schema cache to reload"
2114-
2115-
env = {
2116-
**defaultenv,
2117-
"PGRST_DB_POOL": "2",
2118-
"PGRST_INTERNAL_SCHEMA_CACHE_RELATIONSHIP_LOAD_SLEEP": "5100",
2119-
}
2120-
2121-
with run(env=env, wait_max_seconds=30) as postgrest:
2122-
# reload the schema cache
2123-
response = postgrest.session.get("/rpc/notify_pgrst")
2124-
assert response.status_code == 204
2125-
2126-
postgrest.wait_until_scache_starts_loading()
2127-
2128-
response = postgrest.session.get("/directors?select=id,name,films(title)")
2129-
assert response.status_code == 200
2130-
2131-
assert response.elapsed.total_seconds() > 5
2132-
2133-
2134-
def test_requests_without_resource_embedding_wait_for_schema_cache_reload(defaultenv):
2135-
"requests that use the schema cache without resource embedding wait less for the schema cache to reload"
2136-
2137-
env = {
2138-
**defaultenv,
2139-
"PGRST_DB_POOL": "2",
2140-
"PGRST_INTERNAL_SCHEMA_CACHE_LOAD_SLEEP": "1100",
2141-
"PGRST_INTERNAL_SCHEMA_CACHE_RELATIONSHIP_LOAD_SLEEP": "5000",
2142-
}
2143-
2144-
with run(env=env, wait_max_seconds=30) as postgrest:
2145-
# reload the schema cache
2146-
response = postgrest.session.get("/rpc/notify_pgrst")
2147-
assert response.status_code == 204
2148-
2149-
postgrest.wait_until_scache_starts_loading()
2150-
2151-
response = postgrest.session.get("/films")
2152-
assert response.status_code == 200
2153-
2154-
assert (
2155-
response.elapsed.total_seconds() > 1
2156-
and response.elapsed.total_seconds() < 5
2157-
)
2158-
2159-
21602087
def test_server_timing_transaction_duration(defaultenv, metapostgrest):
21612088
"server-timing transaction duration should be accurate"
21622089

test/observability/ObsHelper.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
118118
, configRoleSettings = mempty
119119
, configRoleIsoLvl = mempty
120120
, configInternalSCQuerySleep = Nothing
121-
, configInternalSCLoadSleep = Nothing
122-
, configInternalSCRelLoadSleep = Nothing
123121
, configServerTimingEnabled = True
124122
}
125123

test/spec/SpecHelper.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
159159
, configRoleSettings = mempty
160160
, configRoleIsoLvl = mempty
161161
, configInternalSCQuerySleep = Nothing
162-
, configInternalSCLoadSleep = Nothing
163-
, configInternalSCRelLoadSleep = Nothing
164162
, configServerTimingEnabled = True
165163
}
166164

0 commit comments

Comments
 (0)