Skip to content

Commit 2ea3dd6

Browse files
committed
refactor: extract top level SchemaCache.tablesFuzzyIndex function
1 parent f81dd29 commit 2ea3dd6

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/library/PostgREST/SchemaCache.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,22 @@ querySchemaCache conf@AppConfig{..} = do
188188
, dbMediaHandlers = HM.union mHdlers initialMediaHandlers -- the custom handlers will override the initial ones
189189
, dbTimezones = tzones
190190

191-
, dbTablesFuzzyIndex =
192-
-- Only build fuzzy index for schemas with a reasonable number of tables
193-
-- Fuzzy.FuzzySet is memory heavy we just don't use it for large schemas
194-
Fuzzy.fromList <$> HM.filter ((< maxDbTablesForFuzzySearch) . length) (HM.fromListWith (<>) ((qiSchema &&& pure . qiName) <$> HM.keys tabsWViewsPks))
191+
, dbTablesFuzzyIndex = tablesFuzzyIndex tabsWViewsPks
195192
}, qsTime)
196193
where
197194
schemas = toList configDbSchemas
198195
isLogDebug = configLogLevel == LogDebug
199196
sqlTimedStmt = sqlTimedStatement isLogDebug
200197
sleepCall = SQL.Statement "select pg_sleep($1 / 1000.0)" (param HE.int4) HD.noResult True
201198

199+
tablesFuzzyIndex :: TablesMap -> TablesFuzzyIndex
200+
tablesFuzzyIndex tabs =
201+
-- Only build fuzzy index for schemas with a reasonable number of tables
202+
-- Fuzzy.FuzzySet is memory heavy we just don't use it for large schemas
203+
Fuzzy.fromList <$>
204+
HM.filter ((< maxDbTablesForFuzzySearch) . length)
205+
(HM.fromListWith (<>) ((qiSchema &&& pure . qiName) <$> HM.keys tabs))
206+
202207
-- | overrides detected relationships with the computed relationships and gets the RelationshipsMap
203208
getOverrideRelationshipsMap :: [Relationship] -> [Relationship] -> RelationshipsMap
204209
getOverrideRelationshipsMap rels cRels =

0 commit comments

Comments
 (0)