@@ -25,6 +25,7 @@ import Data.List qualified as List
25
25
import Data.Map qualified as Map
26
26
import Data.Set qualified as Set
27
27
import Data.Time (UTCTime )
28
+ import Safe (lastMay )
28
29
import Share.Contribution (Contribution (.. ), ContributionStatus (.. ))
29
30
import Share.IDs
30
31
import Share.Postgres qualified as PG
@@ -35,7 +36,6 @@ import Share.Utils.API
35
36
import Share.Web.Errors
36
37
import Share.Web.Share.Contributions.API (ContributionTimelineCursor , ListContributionsCursor )
37
38
import Share.Web.Share.Contributions.Types
38
- import Safe (lastMay )
39
39
40
40
createContribution ::
41
41
-- | Author
@@ -108,7 +108,7 @@ contributionByProjectIdAndNumber projectId contributionNumber = do
108
108
shareContributionByProjectIdAndNumber ::
109
109
ProjectId ->
110
110
ContributionNumber ->
111
- PG. Transaction e (Maybe ShareContribution )
111
+ PG. Transaction e (Maybe ( ShareContribution UserId ) )
112
112
shareContributionByProjectIdAndNumber projectId contributionNumber = do
113
113
PG. query1Row
114
114
[PG. sql |
@@ -126,7 +126,7 @@ shareContributionByProjectIdAndNumber projectId contributionNumber = do
126
126
target_branch_contributor.handle,
127
127
contribution.created_at,
128
128
contribution.updated_at,
129
- author.handle ,
129
+ contribution.author_id ,
130
130
(SELECT COUNT(*) FROM comments comment WHERE comment.contribution_id = contribution.id AND comment.deleted_at IS NULL) as num_comments
131
131
FROM contributions AS contribution
132
132
JOIN projects AS project ON project.id = contribution.project_id
@@ -135,7 +135,6 @@ shareContributionByProjectIdAndNumber projectId contributionNumber = do
135
135
LEFT JOIN users AS source_branch_contributor ON source_branch_contributor.id = source_branch.contributor_id
136
136
JOIN project_branches AS target_branch ON target_branch.id = contribution.target_branch
137
137
LEFT JOIN users AS target_branch_contributor ON target_branch_contributor.id = target_branch.contributor_id
138
- JOIN users AS author ON author.id = contribution.author_id
139
138
WHERE contribution.project_id = #{projectId}
140
139
AND contribution_number = #{contributionNumber}
141
140
|]
@@ -149,7 +148,7 @@ listContributionsByProjectId ::
149
148
Maybe UserId ->
150
149
Maybe ContributionStatus ->
151
150
Maybe ContributionKindFilter ->
152
- PG. Transaction e (Maybe (Cursor ListContributionsCursor ), [ShareContribution ])
151
+ PG. Transaction e (Maybe (Cursor ListContributionsCursor ), [ShareContribution UserId ])
153
152
listContributionsByProjectId projectId limit mayCursor mayUserFilter mayStatusFilter mayKindFilter = do
154
153
let kindFilter = case mayKindFilter of
155
154
Nothing -> " true"
@@ -164,7 +163,7 @@ listContributionsByProjectId projectId limit mayCursor mayUserFilter mayStatusFi
164
163
(contribution.updated_at, contribution.id) < (#{beforeTime}, #{contributionId})
165
164
|]
166
165
addCursor
167
- <$> PG. queryListRows @ ShareContribution
166
+ <$> PG. queryListRows @ ( ShareContribution UserId )
168
167
[PG. sql |
169
168
SELECT
170
169
contribution.id,
@@ -180,7 +179,7 @@ listContributionsByProjectId projectId limit mayCursor mayUserFilter mayStatusFi
180
179
target_branch_contributor.handle,
181
180
contribution.created_at,
182
181
contribution.updated_at,
183
- author.handle ,
182
+ contribution.author_id ,
184
183
(SELECT COUNT(*) FROM comments comment WHERE comment.contribution_id = contribution.id AND comment.deleted_at IS NULL) as num_comments
185
184
FROM contributions AS contribution
186
185
JOIN projects AS project ON project.id = contribution.project_id
@@ -189,7 +188,6 @@ listContributionsByProjectId projectId limit mayCursor mayUserFilter mayStatusFi
189
188
LEFT JOIN users AS source_branch_contributor ON source_branch_contributor.id = source_branch.contributor_id
190
189
JOIN project_branches AS target_branch ON target_branch.id = contribution.target_branch
191
190
LEFT JOIN users AS target_branch_contributor ON target_branch_contributor.id = target_branch.contributor_id
192
- JOIN users AS author ON author.id = contribution.author_id
193
191
WHERE
194
192
^{kindFilter}
195
193
AND ^{cursorFilter}
@@ -200,7 +198,7 @@ listContributionsByProjectId projectId limit mayCursor mayUserFilter mayStatusFi
200
198
LIMIT #{limit}
201
199
|]
202
200
where
203
- addCursor :: [ShareContribution ] -> (Maybe (Cursor ListContributionsCursor ), [ShareContribution ])
201
+ addCursor :: [ShareContribution UserId ] -> (Maybe (Cursor ListContributionsCursor ), [ShareContribution UserId ])
204
202
addCursor xs =
205
203
( lastMay xs <&> \ (ShareContribution {updatedAt, contributionId}) ->
206
204
Cursor (updatedAt, contributionId),
@@ -285,7 +283,7 @@ listContributionsByUserId ::
285
283
Maybe (Cursor (UTCTime , ContributionId )) ->
286
284
Maybe ContributionStatus ->
287
285
Maybe ContributionKindFilter ->
288
- PG. Transaction e (Maybe (Cursor (UTCTime , ContributionId )), [ShareContribution ])
286
+ PG. Transaction e (Maybe (Cursor (UTCTime , ContributionId )), [ShareContribution UserId ])
289
287
listContributionsByUserId callerUserId userId limit mayCursor mayStatusFilter mayKindFilter = do
290
288
let kindFilter = case mayKindFilter of
291
289
Nothing -> " true"
@@ -300,7 +298,7 @@ listContributionsByUserId callerUserId userId limit mayCursor mayStatusFilter ma
300
298
(contribution.updated_at, contribution.id) < (#{beforeTime}, #{contributionId})
301
299
|]
302
300
addCursor
303
- <$> PG. queryListRows @ ShareContribution
301
+ <$> PG. queryListRows @ ( ShareContribution UserId )
304
302
[PG. sql |
305
303
SELECT
306
304
contribution.id,
@@ -316,7 +314,7 @@ listContributionsByUserId callerUserId userId limit mayCursor mayStatusFilter ma
316
314
target_branch_contributor.handle,
317
315
contribution.created_at,
318
316
contribution.updated_at,
319
- author.handle
317
+ contribution.author_id,
320
318
(SELECT COUNT(*) FROM comments comment WHERE comment.contribution_id = contribution.id AND comment.deleted_at IS NULL) as num_comments
321
319
FROM contributions AS contribution
322
320
JOIN projects AS project ON project.id = contribution.project_id
@@ -336,7 +334,7 @@ listContributionsByUserId callerUserId userId limit mayCursor mayStatusFilter ma
336
334
LIMIT #{limit}
337
335
|]
338
336
where
339
- addCursor :: [ShareContribution ] -> (Maybe (Cursor ListContributionsCursor ), [ShareContribution ])
337
+ addCursor :: [ShareContribution UserId ] -> (Maybe (Cursor ListContributionsCursor ), [ShareContribution UserId ])
340
338
addCursor xs =
341
339
( lastMay xs <&> \ (ShareContribution {updatedAt, contributionId}) ->
342
340
Cursor (updatedAt, contributionId),
@@ -345,12 +343,12 @@ listContributionsByUserId callerUserId userId limit mayCursor mayStatusFilter ma
345
343
346
344
-- | Note: Doesn't perform auth checks, the assumption is that if you already have access to
347
345
-- the branchId you have access to all associated contributions.
348
- shareContributionsByBranchOf :: Traversal s t BranchId [ShareContribution ] -> s -> PG. Transaction e t
346
+ shareContributionsByBranchOf :: Traversal s t BranchId [ShareContribution UserId ] -> s -> PG. Transaction e t
349
347
shareContributionsByBranchOf trav s =
350
348
s
351
349
& unsafePartsOf trav %%~ \ branchIds -> do
352
350
contributionsByBranch <-
353
- ( PG. queryListRows @ (PG. Only BranchId PG. :. ShareContribution )
351
+ ( PG. queryListRows @ (PG. Only BranchId PG. :. ShareContribution UserId )
354
352
[PG. sql |
355
353
WITH source_branches(branch_id) AS (
356
354
SELECT * FROM ^{PG.singleColumnTable branchIds}
@@ -370,7 +368,7 @@ shareContributionsByBranchOf trav s =
370
368
target_branch_contributor.handle,
371
369
contribution.created_at,
372
370
contribution.updated_at,
373
- author.handle ,
371
+ contribution.author_id ,
374
372
(SELECT COUNT(*) FROM comments comment WHERE comment.contribution_id = contribution.id AND comment.deleted_at IS NULL) as num_comments
375
373
FROM source_branches
376
374
JOIN project_branches AS source_branch ON source_branch.id = source_branches.branch_id
@@ -380,9 +378,8 @@ shareContributionsByBranchOf trav s =
380
378
LEFT JOIN users AS source_branch_contributor ON source_branch_contributor.id = source_branch.contributor_id
381
379
JOIN project_branches AS target_branch ON target_branch.id = contribution.target_branch
382
380
LEFT JOIN users AS target_branch_contributor ON target_branch_contributor.id = target_branch.contributor_id
383
- JOIN users AS author ON author.id = contribution.author_id
384
381
|]
385
- <&> ( \ (results :: [PG. Only BranchId PG. :. ShareContribution ]) ->
382
+ <&> ( \ (results :: [PG. Only BranchId PG. :. ShareContribution UserId ]) ->
386
383
-- Group by the source branch Id.
387
384
results
388
385
& fmap
0 commit comments