From ae1afe125f93b45b980d7b9273c8955b909bed42 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 ++------------------- 3 files changed, 7 insertions(+), 148 deletions(-) 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 ] ]