From e470c8f8228aae061f402c6bc17e9ef47923316c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Thu, 25 Jul 2024 10:19:20 +0200 Subject: [PATCH] Remove search streams left overs It would kill the server in production environment --- ruby_event_store-browser/elm/src/Api.elm | 28 +----- ruby_event_store-browser/elm/src/Layout.elm | 36 +------- ruby_event_store-browser/elm/src/Search.elm | 91 +------------------ .../elm/tests/DecodersTest.elm | 32 +------ .../elm/tests/SearchTest.elm | 38 -------- 5 files changed, 8 insertions(+), 217 deletions(-) delete mode 100644 ruby_event_store-browser/elm/tests/SearchTest.elm diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index 6ed645f59a..b1b597a0fb 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -1,4 +1,4 @@ -module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), SearchStream, Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getSearchStreams, getStream, searchStreamsDecoder) +module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getStream) import Flags exposing (Flags) import Http @@ -38,10 +38,6 @@ type alias Event = } -type alias SearchStream = - { streamId : String - } - type alias PaginatedList a = { pagination : Pagination.Specification @@ -89,10 +85,6 @@ streamUrl flags streamId = buildUrl (Url.toString flags.apiUrl ++ "/streams") streamId -searchStreamsUrl : Flags -> String -> String -searchStreamsUrl flags query = - buildUrl (Url.toString flags.apiUrl ++ "/search_streams") query - getEvent : (Result Http.Error Event -> msg) -> Flags -> String -> Cmd msg getEvent msgBuilder flags eventId = @@ -110,13 +102,6 @@ getStream msgBuilder flags streamId = } -getSearchStreams : (Result Http.Error (List SearchStream) -> msg) -> Flags -> String -> Cmd msg -getSearchStreams msgBuilder flags query = - Http.get - { url = searchStreamsUrl flags query - , expect = Http.expectJson msgBuilder searchStreamsDecoder - } - eventDecoder : Decoder Event eventDecoder = @@ -172,17 +157,6 @@ eventsDecoder pagination = |> required "links" linksDecoder -searchStreamDecoder : Decoder SearchStream -searchStreamDecoder = - succeed SearchStream - |> required "id" string - - -searchStreamsDecoder : Decoder (List SearchStream) -searchStreamsDecoder = - list searchStreamDecoder - |> field "data" - linksDecoder : Decoder PaginationLinks linksDecoder = diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index f3ca796810..b0be42a2ec 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -1,6 +1,5 @@ port module Layout exposing (Model, Msg, buildModel, subscriptions, update, view, viewIncorrectConfig, viewNotFound) -import Api exposing (SearchStream, getSearchStreams) import Browser exposing (Document) import Browser.Navigation import BrowserTime @@ -25,9 +24,7 @@ type Msg | SearchMsg Search.Msg | ToggleBookmarksMenu | ToggleDialog - | SearchedStreamsFetched (Result Http.Error (List SearchStream)) | OnSelect Search.Stream - | OnQueryChanged Search.Stream | RequestSearch | RequestSearchClose | ToggleBookmark String @@ -73,7 +70,7 @@ subscriptions = buildModel : Model buildModel = { search = - Search.init OnSelect OnQueryChanged + Search.init OnSelect , displayBookmarksMenu = False , bookmarks = [ { itemType = "Stream", label = "Bookmark 1", link = "/" } @@ -87,11 +84,6 @@ goToStream { key, flags } stream = Browser.Navigation.pushUrl key (Route.streamUrl flags.rootUrl stream) -searchStreams : WrappedModel Model -> String -> Cmd Msg -searchStreams { flags } stream = - getSearchStreams SearchedStreamsFetched flags stream - - update : Msg -> WrappedModel Model -> ( WrappedModel Model, Cmd Msg ) update msg model = case msg of @@ -110,9 +102,6 @@ update msg model = ] ) - OnQueryChanged streamName -> - ( model, searchStreams model streamName ) - TimeZoneSelected zoneName -> let defaultTimeZone = @@ -162,29 +151,6 @@ update msg model = ToggleDialog -> ( model, toggleDialog searchModalId ) - SearchedStreamsFetched (Ok streams) -> - let - streams_ = - List.map .streamId streams - - searchModel = - model.internal.search - - newModel = - { searchModel | streams = streams_ } - in - ( { model | internal = Model newModel model.internal.displayBookmarksMenu model.internal.bookmarks }, Cmd.none ) - - SearchedStreamsFetched (Err _) -> - let - searchModel = - model.internal.search - - newModel = - { searchModel | streams = [] } - in - ( { model | internal = Model newModel model.internal.displayBookmarksMenu model.internal.bookmarks }, Cmd.none ) - ToggleBookmark id -> ( model, toggleBookmark id ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 69e1a9d8dd..75cee7a27c 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -13,10 +13,8 @@ type alias Stream = type alias Model a = - { streams : List Stream - , searchedStream : Stream + { searchedStream : Stream , onSelectMsg : Stream -> a - , onQueryMsg : Stream -> a } @@ -35,12 +33,10 @@ emptyStreams = [] -init : (Stream -> a) -> (Stream -> a) -> Model a -init onSelectMsg onQueryMsg = - { streams = emptyStreams - , searchedStream = emptyStreamName +init : (Stream -> a) -> Model a +init onSelectMsg = + { searchedStream = emptyStreamName , onSelectMsg = onSelectMsg - , onQueryMsg = onQueryMsg } @@ -49,27 +45,11 @@ onSelectCmd onSelectMsg stream = Task.perform onSelectMsg (Task.succeed stream) -onQueryChangedCmd : (Stream -> a) -> Stream -> Cmd a -onQueryChangedCmd onQueryMsg stream = - Task.perform onQueryMsg (Task.succeed stream) - - -hasAtLeastThreeChars : Stream -> Bool -hasAtLeastThreeChars stream = - String.length stream >= 3 - - update : Msg -> Model a -> ( Model a, Cmd a ) update msg model = case msg of StreamChanged stream -> - if hasAtLeastThreeChars stream then - ( { model | searchedStream = stream } - , onQueryChangedCmd model.onQueryMsg stream - ) - - else - ( { model | searchedStream = stream }, Cmd.none ) + ( { model | searchedStream = stream }, Cmd.none ) GoToStream stream -> ( { model | searchedStream = emptyStreamName } @@ -77,37 +57,8 @@ update msg model = ) -caseInsensitiveContains : Stream -> Stream -> Maybe Stream -caseInsensitiveContains needle haystack = - let - needleLower = - String.toLower needle - - haystackLower = - String.toLower haystack - in - if String.contains needleLower haystackLower then - Just haystack - - else - Nothing - - -filterStreams : Stream -> List Stream -> List Stream -filterStreams stream streams = - if String.isEmpty stream then - emptyStreams - - else - List.filterMap (caseInsensitiveContains stream) streams - - view : Model a -> Html Msg view model = - let - streams_ = - filterStreams model.searchedStream model.streams - in form [ onSubmit (GoToStream model.searchedStream) ] [ div [ class "relative" ] [ FeatherIcons.search @@ -125,36 +76,4 @@ view model = [ span [ class "text-gray-500 bg-gray-50 font-bold block p-1 border border-gray-300 rounded " ] [ text "ESC" ] ] ] - , viewStreamList streams_ - ] - - -streamsPresent : List Stream -> Bool -streamsPresent streams = - not <| List.isEmpty streams - - -viewStreamList : List Stream -> Html Msg -viewStreamList streams = - if streams |> streamsPresent then - div - [] - [ ul - [ class "mt-4 overflow-auto space-y-2 w-full" ] - (List.map viewStreamListItem streams) - ] - - else - text "" - - -viewStreamListItem : Stream -> Html Msg -viewStreamListItem stream = - li [] - [ a - [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono" - , href ("/streams/" ++ stream) - , onClick (GoToStream stream) - ] - [ text stream ] ] diff --git a/ruby_event_store-browser/elm/tests/DecodersTest.elm b/ruby_event_store-browser/elm/tests/DecodersTest.elm index add018c5d7..a90afd1aa4 100644 --- a/ruby_event_store-browser/elm/tests/DecodersTest.elm +++ b/ruby_event_store-browser/elm/tests/DecodersTest.elm @@ -1,6 +1,6 @@ module DecodersTest exposing (suite) -import Api exposing (eventDecoder, eventsDecoder, searchStreamsDecoder) +import Api exposing (eventDecoder, eventsDecoder) import Expect import Json.Decode import Pagination @@ -143,35 +143,5 @@ suite = , validAt = Time.millisToPosix 1513813785273 } ) - , test "search decoder" <| - \_ -> - let - input = - """ - { - "data": [ - { - "id": "$by_tenant_id_133", - "type": "streams" - }, - { - "id": "$by_tenant_id_444", - "type": "streams" - } - ] - } - """ - - output = - Json.Decode.decodeString searchStreamsDecoder input - in - Expect.equal output - (Ok - [ { streamId = "$by_tenant_id_133" - } - , { streamId = "$by_tenant_id_444" - } - ] - ) ] ] diff --git a/ruby_event_store-browser/elm/tests/SearchTest.elm b/ruby_event_store-browser/elm/tests/SearchTest.elm deleted file mode 100644 index 19b53ddd74..0000000000 --- a/ruby_event_store-browser/elm/tests/SearchTest.elm +++ /dev/null @@ -1,38 +0,0 @@ -module SearchTest exposing (suite) - -import Expect -import Search exposing (filterStreams) -import Test exposing (..) - - -suite : Test -suite = - describe "Suite" - [ describe "filter streams" <| - [ test "filterStreams starting with" <| - \_ -> - Expect.equal - [ "DummyStream$78", "DummyStream$79" ] - (filterStreams "Dum" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams empty" <| - \_ -> - Expect.equal - [] - (filterStreams "" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams non matching" <| - \_ -> - Expect.equal - [] - (filterStreams "foo" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams ending with" <| - \_ -> - Expect.equal - [ "DummyStream$78" ] - (filterStreams "78" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams is case insensitive" <| - \_ -> - Expect.equal - [ "DummyStream$78", "DummyStream$79" ] - (filterStreams "stream" [ "DummyStream$78", "DummyStream$79" ]) - ] - ]