Skip to content

Commit 3374fa2

Browse files
committed
Retry loading diffs that are computing up to 3 timesg
1 parent e3976e6 commit 3374fa2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/UnisonShare/BranchDiffState.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ type DiffError
3434
type BranchDiffState
3535
= Loading
3636
| Computing { numTries : Int }
37-
| Reloading { numtries : Int }
37+
| Reloading { numTries : Int }
3838
| Computed BranchDiff
3939
| Uncomputable DiffError
4040
| Failure Http.Error
4141

4242

4343

44+
--
4445
-- DECODE
4546

4647

src/UnisonShare/Page/ProjectContributionChangesPage.elm

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ init appContext projectRef contribRef changeLineId =
6969
, toggledChangeLines = ToggledChangeLines.empty
7070
, urlFocusedChangeLineId = changeLineId
7171
}
72-
, fetchBranchDiff appContext projectRef contribRef
72+
, fetchBranchDiff appContext projectRef contribRef 1
7373
)
7474

7575

@@ -79,6 +79,7 @@ init appContext projectRef contribRef changeLineId =
7979

8080
type Msg
8181
= FetchBranchDiffFinished (HttpResult BranchDiffState)
82+
| RetryBranchDiffFetch Int
8283
| ToggleChangeDetails ChangeLine
8384
| CopyChangeLinePermalink ChangeLineId
8485
| ScrollTo ChangeLineId
@@ -117,6 +118,15 @@ update appContext projectRef contribRef msg model =
117118
, cmd_
118119
)
119120

121+
Ok ((BranchDiffState.Computing { numTries }) as bds) ->
122+
if numTries >= 3 then
123+
( { model | branchDiff = bds }, Cmd.none )
124+
125+
else
126+
( { model | branchDiff = bds }
127+
, Util.delayMsg 1000 (RetryBranchDiffFetch (numTries + 1))
128+
)
129+
120130
Ok bds ->
121131
( { model | branchDiff = bds }, Cmd.none )
122132

@@ -125,6 +135,11 @@ update appContext projectRef contribRef msg model =
125135
in
126136
( model_, cmd )
127137

138+
RetryBranchDiffFetch numTries ->
139+
( { model | branchDiff = BranchDiffState.Reloading { numTries = numTries } }
140+
, fetchBranchDiff appContext projectRef contribRef numTries
141+
)
142+
128143
ScrollTo changeLineId ->
129144
( model, scrollTo changeLineId )
130145

@@ -179,10 +194,10 @@ scrollTo changeLineId =
179194
ScrollTo.scrollTo_ NoOp "page-content" (ChangeLineId.toDomId changeLineId) 16
180195

181196

182-
fetchBranchDiff : AppContext -> ProjectRef -> ContributionRef -> Cmd Msg
183-
fetchBranchDiff appContext projectRef contributionRef =
197+
fetchBranchDiff : AppContext -> ProjectRef -> ContributionRef -> Int -> Cmd Msg
198+
fetchBranchDiff appContext projectRef contributionRef numTries =
184199
ShareApi.projectContributionDiff projectRef contributionRef
185-
|> HttpApi.toRequest (BranchDiffState.decode 1) FetchBranchDiffFinished
200+
|> HttpApi.toRequest (BranchDiffState.decode numTries) FetchBranchDiffFinished
186201
|> HttpApi.perform appContext.api
187202

188203

0 commit comments

Comments
 (0)