Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: remove legacy search helper #1102

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading