Skip to content

Commit

Permalink
Merge branch 'master' into bump-elastic-version
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 6, 2024
2 parents b194529 + 4548a0c commit b179c07
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/Monocle/Backend/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ upgradeConfigV1 = do
let entity = CrawlerPB.EntityTypeENTITY_TYPE_PROJECT
search = BH.mkSearch (Just $ crawlerMDQuery entity crawlerName) Nothing
index <- getIndexName
resp <- fmap BH.hitSource <$> Q.simpleSearchLegacy index search
resp <- fmap BH.hitSource <$> esSearchByIndex index search
pure $ catMaybes resp
isCrawlerLastCommitAtIsDefault :: Config.Index -> ECrawlerMetadata -> Bool
isCrawlerLastCommitAtIsDefault
Expand Down Expand Up @@ -921,7 +921,7 @@ crawlerMDQuery entity crawlerName =
getLastUpdated :: MonoQuery :> es => IndexEffects es => Config.Crawler -> CrawlerPB.EntityType -> Word32 -> Eff es (Maybe ECrawlerMetadataObject)
getLastUpdated crawler entity offset = do
index <- getIndexName
resp <- fmap BH.hitSource <$> Q.simpleSearchLegacy index search
resp <- fmap BH.hitSource <$> esSearchByIndex index search
case nonEmpty (catMaybes resp) of
Nothing -> pure Nothing
Just xs ->
Expand Down
4 changes: 0 additions & 4 deletions src/Monocle/Backend/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import Streaming.Prelude qualified as Streaming
import Monocle.Effects
import Proto3.Suite (Enumerated (Enumerated))

-- Legacy wrappers
simpleSearchLegacy :: (LoggerEffect :> es, Error ElasticError :> es, ElasticEffect :> es, FromJSON a) => BH.IndexName -> BH.Search -> Eff es [BH.Hit a]
simpleSearchLegacy indexName search = BH.hits . BH.searchHits <$> esSearchLegacy indexName search

-------------------------------------------------------------------------------
-- Low level wrappers for bloodhound.
{- TODO: migrate to proper effect
Expand Down
21 changes: 4 additions & 17 deletions src/Monocle/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ esSearch :: (Error ElasticError :> es, ElasticEffect :> es, ToJSON body, FromJSO
esSearch iname body scrollReq = do
runBHIOSafe "esSearch" body $ BHR.search iname body scrollReq

-- | This is similar to esScanSearch, but 'searchByIndex' respects search size and sort order
esSearchByIndex :: (Error ElasticError :> es, ElasticEffect :> es, ToJSON body, FromJSONField resp) => BH.IndexName -> body -> Eff es [BH.Hit resp]
esSearchByIndex iname body = BH.hits . BH.searchHits <$> esSearch iname body BHR.NoScroll

esAdvance :: (Error ElasticError :> es, ElasticEffect :> es, FromJSON resp) => BH.ScrollId -> Eff es (BH.SearchResult resp)
esAdvance scroll = do
runBHIOSafe "esAdvance" scroll $ BHR.advance scroll
Expand Down Expand Up @@ -502,24 +506,7 @@ esUpdateDocument :: (Error ElasticError :> es, ElasticEffect :> es) => ToJSON a
esUpdateDocument iname ids body doc = do
runBHIOSafe "esUpdateDocument" body $ BH.updateDocument iname ids body doc

-- Legacy wrappers
esSearchLegacy :: (LoggerEffect :> es, Error ElasticError :> es, ElasticEffect :> es, FromJSON a) => BH.IndexName -> BH.Search -> Eff es (BH.SearchResult a)
esSearchLegacy indexName search = do
(rawResp, resp) <- runBHIOSafe "esSearchLegacy" search do
-- logText . decodeUtf8 . encode $ search
rawResp <- BH.searchByIndex indexName search
-- logText $ show rawResp
(\resp -> (rawResp, resp)) <$> BH.parseEsResponse rawResp
case resp of
Left e -> handleError e rawResp
Right x -> pure x
where
handleError resp rawResp = do
logWarn "Elastic response failed" ["status" .= BH.errorStatus resp, "message" .= BH.errorMessage resp]
error $ "Elastic response failed: " <> show rawResp

------------------------------------------------------------------
--

-- | HTTP Effect

Expand Down

0 comments on commit b179c07

Please sign in to comment.