66 LICENSE file in the root directory of this source tree.
77-}
88
9+ {-# LANGUAGE OverloadedRecordDot #-}
910module Glean.Glass.RepoMapping
1011 ( getRepoMapping
1112 , fixedRepoMapping
@@ -16,23 +17,57 @@ module Glean.Glass.RepoMapping
1617 , Mirror (.. )
1718 ) where
1819
20+ import qualified Data.Map.Strict as Map
21+ import Data.Maybe
1922import Data.Set (Set )
2023import qualified Data.Set as Set
21- import qualified Data.Map.Strict as Map
24+ import Data.Text (Text )
25+
26+ import Thrift.Protocol.JSON (deserializeJSON )
27+
28+ import qualified Glean.Util.ThriftSource as ThriftSource
29+ import Glean.Util.ConfigProvider
2230
2331import Glean.Glass.Base
2432 ( GleanDBName (.. )
2533 , RepoMapping (.. )
2634 , GleanDBSelector (.. )
2735 )
28- import Glean.Glass.Types ( Language (.. ), RepoName (.. ) )
29- import Data.Text (Text )
36+ import qualified Glean.Glass.Repomapping.Types as Config
37+ import Glean.Glass.SymbolId ( fromShortCode )
38+ import Glean.Glass.Types
3039
31- getRepoMapping :: IO RepoMapping
32- getRepoMapping = return RepoMapping
33- { gleanIndices = gleanIndices_
34- , gleanAttrIndices = Map. empty
35- }
40+ getRepoMapping :: ConfigProvider cfg => cfg -> IO RepoMapping
41+ getRepoMapping cfg = ThriftSource. load cfg repoMappingSource
42+
43+ toRepoMapping :: Config. RepoMapping -> RepoMapping
44+ toRepoMapping rm =
45+ RepoMapping
46+ { gleanIndices = Map. fromList
47+ [ (RepoName repo, mapMaybe toSelector selectors)
48+ | (repo, selectors) <- Map. toList rm. indices
49+ ]
50+ , gleanAttrIndices = Map. empty
51+ -- can do this later if necessary. We would have to pattern-match
52+ -- on a string and map to the ToAttributes key type.
53+ }
54+ where
55+ toSelector :: Config. DbSelector -> Maybe GleanDBSelector
56+ toSelector dbsel = do
57+ lang <- fromShortCode dbsel. language
58+ return GleanDBSelector
59+ { dbName = GleanDBName dbsel. name
60+ , language = lang
61+ , branchName = dbsel. branch
62+ }
63+
64+ repoMappingSource :: ThriftSource. ThriftSource RepoMapping
65+ repoMappingSource =
66+ ThriftSource. configWithDeserializerDefault " glass/repomapping" $
67+ \ bytes -> toRepoMapping <$> deserializeJSON bytes
68+ -- doing the translation to RepoMapping in the deserializer ensures
69+ -- that this is cached, we don't have to worry about the translation
70+ -- happening on every request.
3671
3772fixedRepoMapping :: RepoMapping
3873fixedRepoMapping = RepoMapping
0 commit comments