Skip to content

Commit f17d515

Browse files
committed
More paging logic fixes
1 parent ac9891e commit f17d515

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

share-api/src/Share/Postgres/Causal/Queries.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,9 @@ pagedCausalAncestors ::
10031003
pagedCausalAncestors rootCausalId limit mayCursor =
10041004
do
10051005
let (filter, ordering, maybeReverse) = case mayCursor of
1006-
Nothing -> mempty
1007-
Just (Cursor (hash, depth) Next) -> ([sql| WHERE (h.causal_depth, h.hash) > (#{depth}, #{hash}) |], [sql| ORDER BY h.causal_depth DESC, h.hash ASC |], id)
1008-
Just (Cursor (hash, depth) Previous) -> ([sql| WHERE (h.causal_depth, h.hash) < (#{depth}, #{hash}) |], [sql| ORDER BY h.causal_depth ASC, h.hash DESC |], reverse)
1006+
Nothing -> (mempty, [sql| ORDER BY (h.causal_depth, h.causal_hash) DESC |], id)
1007+
Just (Cursor (hash, depth) Next) -> ([sql| WHERE (h.causal_depth, h.causal_hash) < (#{depth}, #{hash}) |], [sql| ORDER BY (h.causal_depth, h.causal_hash) DESC |], id)
1008+
Just (Cursor (hash, depth) Previous) -> ([sql| WHERE (h.causal_depth, h.causal_hash) > (#{depth}, #{hash}) |], [sql| ORDER BY (h.causal_depth , h.causal_hash) ASC |], reverse)
10091009
rawResults <-
10101010
queryListRows @(CausalHash, CausalDepth)
10111011
[sql|
@@ -1022,8 +1022,8 @@ pagedCausalAncestors rootCausalId limit mayCursor =
10221022
JOIN causal_depth cd ON c.id = cd.causal_id
10231023
) SELECT h.causal_hash, h.causal_depth
10241024
FROM history h
1025-
^{ordering}
10261025
^{filter}
1026+
^{ordering}
10271027
LIMIT #{limit + 1}
10281028
|]
10291029
let hasPrevPage = case mayCursor of
@@ -1036,6 +1036,7 @@ pagedCausalAncestors rootCausalId limit mayCursor =
10361036
Just (Cursor _ Previous) -> True
10371037
pure rawResults
10381038
<&> maybeReverse
1039+
<&> take (fromIntegral (getLimit limit))
10391040
<&> pagedOn id
10401041
<&> guardPaged hasPrevPage hasNextPage
10411042
<&> fmap fst

share-api/src/Share/Web/Share/Branches/Impl.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import Share.Web.Share.Projects.Types (projectToAPI)
5050
import Share.Web.Share.Types
5151
import U.Codebase.HashTags (CausalHash)
5252
import Unison.Codebase.Path qualified as Path
53+
import Unison.Debug qualified as Debug
5354
import Unison.HashQualified qualified as HQ
5455
import Unison.Name (Name)
5556
import Unison.NameSegment.Internal (NameSegment (..))
@@ -507,11 +508,13 @@ branchHistoryEndpoint (AuthN.MaybeAuthedUserID callerUserId) userHandle projectS
507508
let codebaseLoc = Codebase.codebaseLocationForProjectBranchCodebase projectOwnerUserId contributorId
508509
let codebase = Codebase.codebaseEnv authZReceipt codebaseLoc
509510
causalId <- resolveRootHash codebase branchHead Nothing
511+
Debug.debugM Debug.Temp "branchHistoryEndpoint Resolved causalId: " causalId
510512
PG.runTransaction do
511513
history <-
512514
CausalQ.pagedCausalAncestors causalId limit mayCursor
513515
<&> fmap \(causalHash) ->
514516
BranchHistoryCausalEntry (BranchHistoryCausal {causalHash})
517+
Debug.debugM Debug.Temp "branchHistoryEndpoint Retrieved history entries: " (history)
515518
pure $
516519
BranchHistoryResponse
517520
{ projectRef,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"body": {
3+
"branchRef": "main",
4+
"history": {
5+
"items": [],
6+
"nextCursor": null,
7+
"prevCursor": null
8+
},
9+
"projectRef": "@transcripts/branch-with-history"
10+
},
11+
"status": [
12+
{
13+
"status_code": 200
14+
}
15+
]
16+
}

transcripts/share-apis/branches/prelude.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
```ucm
2-
branch-with-history/main> builtins.merge builtins
3-
```
4-
51
```unison
62
x1 = 1
73
```
@@ -17,6 +13,7 @@ branch-with-history/main> alias.term x6 x7
1713
branch-with-history/main> alias.term x7 x8
1814
branch-with-history/main> alias.term x8 x9
1915
branch-with-history/main> alias.term x9 x10
16+
branch-with-history/main> history
2017
branch-with-history/main> push @transcripts/branch-with-history/main
2118
```
2219

transcripts/share-apis/branches/run.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ fetch "$test_user" GET branch-details-deleted '/users/test/projects/publictestpr
5959
# Add some history to a branch.
6060
transcript_ucm transcript prelude.md
6161

62-
fetch "$transcripts_user" GET branch-history '/users/transcripts/projects/branch-browse/branches/main/history?limit=3'
62+
fetch "$transcripts_user" GET branch-history '/users/transcripts/projects/branch-with-history/branches/main/history?limit=3'

0 commit comments

Comments
 (0)