Skip to content

Commit 38fa901

Browse files
committed
revert Json use for hits
1 parent 7404f22 commit 38fa901

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/Monocle/Backend/Queries.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ doAdvanceScrollBH scroll = do
6464
measureQueryM (Aeson.object ["scrolling" .= ("advancing..." :: Text)]) do
6565
esAdvance scroll
6666

67-
doSearchHitBH :: QEffects es => FromJSON a => BH.Search -> Eff es (BH.SearchResult a)
68-
doSearchHitBH payload = do
67+
doSearchHitBH :: QEffects es => (Json.Value -> Either Text a) -> BH.Search -> Eff es [a]
68+
doSearchHitBH parseHit payload = do
6969
measureQueryM payload do
7070
index <- getIndexName
71-
esSearchHit index payload
71+
esSearchHit parseHit index payload
7272

7373
-- | Call the count endpoint
7474
doCountBH :: QEffects es => BH.Query -> Eff es Count
@@ -156,10 +156,11 @@ doSearch orderM limit = do
156156
SearchPB.Order_DirectionDESC -> BH.Descending
157157

158158
-- | Get search results hits, as fast as possible
159-
doFastSearch :: QEffects es => FromJSON a => Word32 -> Eff es (BH.SearchResult a)
160-
doFastSearch limit = do
159+
doFastSearch :: QEffects es => (Json.Value -> Either Text a) -> Word32 -> Eff es [a]
160+
doFastSearch parseHit limit = do
161161
query <- getQueryBH
162162
doSearchHitBH
163+
parseHit
163164
(BH.mkSearch query Nothing)
164165
{ BH.size = BH.Size $ fromInteger $ toInteger $ max 50 limit
165166
}
@@ -448,14 +449,13 @@ data JsonChangeEvent = JsonChangeEvent
448449
, jceAuthor :: Json.ShortText
449450
}
450451

451-
instance FromJSON JsonChangeEvent where
452-
parseJSON =
453-
Aeson.withObject "JsonChangeEvent" $ \o ->
454-
JsonChangeEvent
455-
<$> (o .: "created_at")
456-
<*> (o .: "on_created_at")
457-
<*> (o .: "change_id")
458-
<*> ((.: "muid") =<< o .: "author")
452+
decodeJsonChangeEvent :: Json.Value -> Maybe JsonChangeEvent
453+
decodeJsonChangeEvent v = do
454+
jceCreatedAt <- Json.getDate =<< Json.getAttr "created_at" v
455+
jceOnCreatedAt <- Json.getDate =<< Json.getAttr "on_created_at" v
456+
jceChangeId <- Json.getString =<< Json.getAttr "change_id" v
457+
jceAuthor <- Json.getString =<< Json.getAttr "muid" =<< Json.getAttr "author" v
458+
pure $ JsonChangeEvent {..}
459459

460460
firstEventDuration :: FirstEvent -> Pico
461461
firstEventDuration FirstEvent {..} = elapsedSeconds feChangeCreatedAt feCreatedAt
@@ -468,7 +468,7 @@ firstEventOnChanges = do
468468
(minDate, _) <- getQueryBound
469469

470470
-- Collect all the events
471-
result <- mapMaybe BH.hitSource . BH.hits . BH.searchHits <$> doFastSearch 10000
471+
result <- catMaybes <$> doFastSearch (Right . decodeJsonChangeEvent) 10000
472472

473473
-- Group by change_id
474474
let changeMap :: [NonEmpty JsonChangeEvent]

0 commit comments

Comments
 (0)