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

fix: reduce excessive API calls #810

Merged
merged 22 commits into from
Aug 7, 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 cypress/fixtures/services_5.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"number": 2,
"name": "service-b",
"stage": "",
"status": "success",
"status": "running",
"error": "",
"exit_code": 2,
"created": 1572029883,
"started": 1572029928,
"finished": 1572029935,
"finished": 0,
"host": "",
"runtime": "docker",
"distribution": "linux"
Expand Down
4 changes: 2 additions & 2 deletions cypress/fixtures/steps_5.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"number": 2,
"name": "build",
"stage": "",
"status": "success",
"status": "running",
"error": "",
"exit_code": 2,
"created": 1572029883,
"started": 1572029928,
"finished": 1572029935,
"finished": 0,
"host": "",
"runtime": "docker",
"distribution": "linux"
Expand Down
7 changes: 6 additions & 1 deletion src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, addAlertError, addAlertSuccess, addDeployment, addFavorites, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, approveBuild, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getCurrentUserShared, getDashboard, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSettings, getSharedSecret, getSharedSecrets, getWorkers, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorite, updateOrgSecret, updateRepo, updateRepoSchedule, updateRepoSecret, updateSettings, updateSharedSecret, updateSourceReposShared
, addAlertError, addAlertSuccess, addDeployment, addFavorites, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, approveBuild, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getCurrentUserShared, getDashboard, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSettings, getSharedSecret, getSharedSecrets, getWorkers, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorite, updateOrgSecret, updateRepo, updateRepoHooksShared, updateRepoSchedule, updateRepoSecret, updateSettings, updateSharedSecret, updateSourceReposShared
)

{-|
Expand Down Expand Up @@ -626,6 +626,11 @@ getRepoHooksShared options =
SendSharedMsg <| Shared.Msg.GetRepoHooks options


updateRepoHooksShared : { hooks : WebData (List Vela.Hook) } -> Effect msg
updateRepoHooksShared options =
SendSharedMsg <| Shared.Msg.UpdateRepoHooks options


redeliverHook :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down
52 changes: 35 additions & 17 deletions src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -328,24 +328,42 @@ update props shared route msg model =

-- REFRESH
Tick options ->
let
isBuildRunning =
case model.build of
RemoteData.Success build ->
build.finished == 0

_ ->
True

getRepoBuildsEffect =
Effect.getRepoBuildsShared
{ pageNumber = Nothing
, perPage = Nothing
, maybeEvent = Nothing
, org = props.org
, repo = props.repo
}

runEffects =
if isBuildRunning then
[ getRepoBuildsEffect
, Effect.getBuild
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetBuildResponse
, org = props.org
, repo = props.repo
, build = props.build
}
]

else
[ getRepoBuildsEffect ]
in
( model
, Effect.batch
[ Effect.getRepoBuildsShared
{ pageNumber = Nothing
, perPage = Nothing
, maybeEvent = Nothing
, org = props.org
, repo = props.repo
}
, Effect.getBuild
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetBuildResponse
, org = props.org
, repo = props.repo
, build = props.build
}
]
, Effect.batch runEffects
)


Expand Down
37 changes: 20 additions & 17 deletions src/elm/Layouts/Default/Repo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,27 @@ update props route msg model =

-- REFRESH
Tick options ->
let
-- the hooks page has its own refresh call for hooks;
-- this is to prevent double calls
isNotOnHooksPage =
route.path /= Route.Path.Org__Repo__Hooks { org = props.org, repo = props.repo }

runEffect =
if isNotOnHooksPage then
Effect.getRepoHooksShared
{ pageNumber = Nothing
, perPage = Nothing
, maybeEvent = Nothing
, org = props.org
, repo = props.repo
}

else
Effect.none
in
( model
, Effect.batch
[ Effect.getCurrentUserShared {}
, Effect.getRepoBuildsShared
{ pageNumber = Nothing
, perPage = Nothing
, maybeEvent = Nothing
, org = props.org
, repo = props.repo
}
, Effect.getRepoHooksShared
{ pageNumber = Nothing
, perPage = Nothing
, maybeEvent = Nothing
, org = props.org
, repo = props.repo
}
]
, runEffect
)


Expand Down
24 changes: 1 addition & 23 deletions src/elm/Pages/Dash/Secrets/Engine_/Org/Org_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,7 @@ update shared route msg model =

-- REFRESH
Tick options ->
( model
, Effect.batch
[ Effect.getOrgSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetOrgSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, engine = route.params.engine
, org = route.params.org
}
, Effect.getSharedSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetSharedSecretsResponse
, pageNumber = Nothing
, perPage = Nothing
, engine = route.params.engine
, org = route.params.org
, team = "*"
}
]
)
( model, Effect.none )



Expand Down
24 changes: 1 addition & 23 deletions src/elm/Pages/Dash/Secrets/Engine_/Repo/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -204,29 +204,7 @@ update shared route msg model =

-- REFRESH
Tick options ->
( model
, Effect.batch
[ Effect.getRepoSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetRepoSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, engine = route.params.engine
, org = route.params.org
, repo = route.params.repo
}
, Effect.getOrgSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetOrgSecretsResponse
, pageNumber = Nothing
, perPage = Nothing
, engine = route.params.engine
, org = route.params.org
}
]
)
( model, Effect.none )



Expand Down
13 changes: 1 addition & 12 deletions src/elm/Pages/Dash/Secrets/Engine_/Shared/Org_/Team_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,7 @@ update shared route msg model =

-- REFRESH
Tick options ->
( model
, Effect.getSharedSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetSharedSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, engine = route.params.engine
, org = route.params.org
, team = route.params.team
}
)
( model, Effect.none )



Expand Down
2 changes: 1 addition & 1 deletion src/elm/Pages/Home_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ update msg model =
-- REFRESH
Tick options ->
( model
, Effect.getCurrentUserShared {}
, Effect.none
)


Expand Down
11 changes: 1 addition & 10 deletions src/elm/Pages/Org_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,7 @@ update shared route msg model =

-- REFRESH
Tick options ->
( model
, Effect.getOrgRepos
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetOrgReposResponse
, org = route.params.org
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
}
)
( model, Effect.none )



Expand Down
Loading
Loading