-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy path0001-Performance-updates-for-loading-submissions-in-marat.patch
More file actions
664 lines (643 loc) · 25.4 KB
/
Copy path0001-Performance-updates-for-loading-submissions-in-marat.patch
File metadata and controls
664 lines (643 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
From 01e80cbf02a6286f3f39c990093dd220f963a7a1 Mon Sep 17 00:00:00 2001
From: jmgasper <jmgasper@gmail.com>
Date: Thu, 2 Jul 2026 14:13:50 +1000
Subject: [PATCH] Performance updates for loading submissions in marathon
matches
---
__tests__/shared/services/submissions.js | 25 +++
.../shared/utils/mm-review-summations.test.js | 48 +++++
.../Submissions/SubmissionRow/index.jsx | 19 +-
.../challenge-detail/Submissions/index.jsx | 186 +++++++++++++++---
.../containers/challenge-detail/index.jsx | 13 +-
src/shared/services/submissions.js | 26 ++-
src/shared/utils/mm-review-summations.js | 49 ++++-
7 files changed, 323 insertions(+), 43 deletions(-)
diff --git a/__tests__/shared/services/submissions.js b/__tests__/shared/services/submissions.js
index d05820bfa..9e2060b22 100644
--- a/__tests__/shared/services/submissions.js
+++ b/__tests__/shared/services/submissions.js
@@ -104,4 +104,29 @@ describe('submissions service', () => {
expect(global.fetch).toHaveBeenCalledTimes(1);
expect(result.data).toEqual([{ id: 'submission-only-page' }]);
});
+
+ it('passes latest and member filters to the submissions API', async () => {
+ global.fetch.mockResolvedValueOnce({
+ ok: true,
+ json: () => Promise.resolve({
+ data: [{ id: 'submission-latest' }],
+ meta: {
+ page: 1,
+ perPage: 100,
+ totalPages: 1,
+ },
+ }),
+ });
+
+ await getChallengeSubmissions('token-v3', 'challenge-id', {
+ isLatest: true,
+ memberId: '1001',
+ });
+
+ expect(global.fetch).toHaveBeenCalledTimes(1);
+ expect(global.fetch).toHaveBeenCalledWith(
+ `${baseUrl}?challengeId=challenge-id&perPage=500&page=1&isLatest=true&memberId=1001`,
+ expect.objectContaining({ method: 'GET' }),
+ );
+ });
});
diff --git a/__tests__/shared/utils/mm-review-summations.test.js b/__tests__/shared/utils/mm-review-summations.test.js
index cd82a0c48..781983745 100644
--- a/__tests__/shared/utils/mm-review-summations.test.js
+++ b/__tests__/shared/utils/mm-review-summations.test.js
@@ -188,6 +188,54 @@ describe('buildMmSubmissionData', () => {
]);
});
+ it('keeps latest-only rows compact while preserving member submission count', () => {
+ const reviewSummations = [
+ {
+ aggregateScore: 10,
+ id: 'summation-old',
+ isProvisional: true,
+ reviewedDate: '2026-04-09T04:00:00.000Z',
+ submissionId: 'submission-old',
+ submitterHandle: 'ctrucza',
+ submitterId: '16064986',
+ },
+ {
+ aggregateScore: 20,
+ id: 'summation-latest',
+ isProvisional: true,
+ reviewedDate: '2026-04-09T05:00:00.000Z',
+ submissionId: 'submission-latest',
+ submitterHandle: 'ctrucza',
+ submitterId: '16064986',
+ },
+ ];
+ const rawSubmissions = [
+ {
+ createdAt: '2026-04-09T05:00:55.279Z',
+ id: 'submission-latest',
+ isLatest: true,
+ memberId: '16064986',
+ submissionCount: 7,
+ submittedDate: '2026-04-09T05:00:55.279Z',
+ submitterHandle: 'ctrucza',
+ },
+ ];
+
+ const result = buildMmSubmissionData(reviewSummations, rawSubmissions);
+
+ expect(result).toHaveLength(1);
+ expect(result[0]).toEqual(expect.objectContaining({
+ member: 'ctrucza',
+ submissionCount: 7,
+ }));
+ expect(result[0].submissions).toEqual([
+ expect.objectContaining({
+ provisionalScore: 20,
+ submissionId: 'submission-latest',
+ }),
+ ]);
+ });
+
it('uses reviewedDate before import createdAt for review summation times', () => {
const reviewSummations = [
{
diff --git a/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx b/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx
index 3ed8f963c..59dcbbde3 100644
--- a/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx
+++ b/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx
@@ -11,6 +11,7 @@ import { Modal } from 'topcoder-react-ui-kit';
import IconClose from 'assets/images/icon-close-green.svg';
import moment from 'moment';
+import LoadingIndicator from 'components/LoadingIndicator';
import FailedSubmissionTooltip from '../FailedSubmissionTooltip';
import InReview from '../../icons/in-review.svg';
import Queued from '../../icons/queued.svg';
@@ -21,7 +22,7 @@ import style from './style.scss';
export default function SubmissionRow({
isMM, isRDM, openHistory, member, submissions, toggleHistory, challengeStatus,
showFinalResults, finalRank, provisionalRank, onShowPopup, rating, viewAsTable,
- numWinners, auth, isLoggedIn, isF2F, isBugHunt,
+ numWinners, auth, isLoggedIn, isF2F, isBugHunt, submissionCount, loadingHistory,
}) {
const submissionList = Array.isArray(submissions) ? submissions : [];
const latestSubmission = submissionList[0] || {};
@@ -114,7 +115,9 @@ export default function SubmissionRow({
const memberLinkTarget = `${_.includes(window.origin, 'www') ? '_self' : '_blank'}`;
const memberForHistory = memberHandle || memberDisplay;
const latestSubmissionId = latestSubmission.submissionId || latestSubmission.id || 'N/A';
- const submissionCount = submissionList.length;
+ const displaySubmissionCount = _.isFinite(submissionCount)
+ ? submissionCount
+ : submissionList.length;
return (
<div styleName={`wrapper ${viewAsTable ? 'wrapper-as-table' : ''} `}>
@@ -181,7 +184,7 @@ export default function SubmissionRow({
>
<span styleName="text">
History (
- {submissionCount}
+ {displaySubmissionCount}
)
</span>
</a>
@@ -237,7 +240,7 @@ export default function SubmissionRow({
>
<span styleName="text">
History (
- {submissionCount}
+ {displaySubmissionCount}
)
</span>
</a>
@@ -305,7 +308,9 @@ export default function SubmissionRow({
</div>
<div styleName="table-body">
{
- submissionList.map((submissionHistory, index) => (
+ loadingHistory ? (
+ <LoadingIndicator />
+ ) : submissionList.map((submissionHistory, index) => (
<SubmissionHistoryRow
showFinalResults={showFinalResults}
isMM={isMM}
@@ -347,6 +352,8 @@ SubmissionRow.defaultProps = {
isLoggedIn: false,
isF2F: false,
isBugHunt: false,
+ loadingHistory: false,
+ submissionCount: null,
};
SubmissionRow.propTypes = {
@@ -397,6 +404,8 @@ SubmissionRow.propTypes = {
onShowPopup: PT.func.isRequired,
viewAsTable: PT.bool.isRequired,
isLoggedIn: PT.bool,
+ loadingHistory: PT.bool,
numWinners: PT.number.isRequired,
auth: PT.shape().isRequired,
+ submissionCount: PT.number,
};
diff --git a/src/shared/components/challenge-detail/Submissions/index.jsx b/src/shared/components/challenge-detail/Submissions/index.jsx
index d9138671c..4c1dab6e4 100644
--- a/src/shared/components/challenge-detail/Submissions/index.jsx
+++ b/src/shared/components/challenge-detail/Submissions/index.jsx
@@ -24,6 +24,7 @@ import SortIcon from 'assets/images/icon-sort.svg';
import { shouldShowFinalMmResults as resolveShouldShowFinalMmResults } from 'utils/challenge-detail/mm-final-results';
import { getSubmissionId } from 'utils/submissions';
import { compressFiles } from 'utils/files';
+import { buildMmSubmissionData } from 'utils/mm-review-summations';
import { getChallengeSubmissions as getChallengeSubmissionsService } from 'services/submissions';
import sortList from 'utils/challenge-detail/sort';
@@ -79,6 +80,15 @@ function getSubmissionMemberId(submission = {}) {
).trim();
}
+/**
+ * Returns a stable key used for cached Marathon Match member history.
+ * @param {Object} submission Member-grouped Marathon Match submission row.
+ * @return {String} Stable member key.
+ */
+function getMmSubmissionHistoryKey(submission = {}) {
+ return _.toString(submission.memberId || submission.member || '').trim();
+}
+
/**
* Resolves a display handle from the v5/v6 submission shapes used by the tab.
* @param {Object} submission Submission record.
@@ -367,6 +377,8 @@ class SubmissionsComponent extends React.Component {
completeSubmissions: null,
completeSubmissionsChallengeId: '',
loadingCompleteSubmissionsForChallengeId: '',
+ loadingMmSubmissionHistoryByMember: {},
+ mmSubmissionHistoryByMember: {},
};
this.completeSubmissionsRequestId = 0;
this.unmounted = false;
@@ -377,6 +389,8 @@ class SubmissionsComponent extends React.Component {
this.sortSubmissions = this.sortSubmissions.bind(this);
this.shouldShowFinalMmResults = this.shouldShowFinalMmResults.bind(this);
this.loadCompleteSubmissions = this.loadCompleteSubmissions.bind(this);
+ this.handleToggleSubmissionHistory = this.handleToggleSubmissionHistory.bind(this);
+ this.loadMmSubmissionHistory = this.loadMmSubmissionHistory.bind(this);
}
componentDidMount() {
@@ -390,7 +404,7 @@ class SubmissionsComponent extends React.Component {
}
if (isMM) {
- loadMMSubmissions(challenge.id, auth.tokenV3);
+ loadMMSubmissions(challenge.id, auth.tokenV3, { latestOnly: true });
} else {
this.loadCompleteSubmissions();
}
@@ -598,6 +612,113 @@ class SubmissionsComponent extends React.Component {
});
}
+ /**
+ * Loads all historical submissions for one Marathon Match member.
+ * @param {Object} submission Member-grouped Marathon Match submission row.
+ * @return {Promise<void>|undefined} Resolves after the history cache updates.
+ */
+ loadMmSubmissionHistory(submission) {
+ const key = getMmSubmissionHistoryKey(submission);
+ const memberId = _.toString(_.get(submission, 'memberId', '')).trim();
+ const { auth, challenge } = this.props;
+ const challengeId = _.toString(_.get(challenge, 'id', ''));
+
+ if (!key || !memberId || !challengeId) {
+ return undefined;
+ }
+
+ const {
+ loadingMmSubmissionHistoryByMember,
+ mmSubmissionHistoryByMember,
+ } = this.state;
+ if (loadingMmSubmissionHistoryByMember[key] || mmSubmissionHistoryByMember[key]) {
+ return undefined;
+ }
+
+ this.setState({
+ loadingMmSubmissionHistoryByMember: {
+ ...loadingMmSubmissionHistoryByMember,
+ [key]: true,
+ },
+ });
+
+ return getChallengeSubmissionsService(_.get(auth, 'tokenV3'), challengeId, { memberId })
+ .then(({ data }) => {
+ if (this.unmounted) {
+ return;
+ }
+ const memberHistoryRows = buildMmSubmissionData([], Array.isArray(data) ? data : []);
+ const memberHistory = _.find(
+ memberHistoryRows,
+ row => _.toString(row.memberId || row.member) === key,
+ );
+ const currentAttemptsById = new Map(
+ (submission.submissions || []).map(attempt => [
+ _.toString(attempt.submissionId || attempt.id),
+ attempt,
+ ]),
+ );
+ const historySubmissions = _.get(memberHistory, 'submissions', [])
+ .map((attempt) => {
+ const attemptId = _.toString(attempt.submissionId || attempt.id);
+ const existingAttempt = currentAttemptsById.get(attemptId) || {};
+ return {
+ ...existingAttempt,
+ ...attempt,
+ finalScore: _.isNil(attempt.finalScore)
+ ? existingAttempt.finalScore
+ : attempt.finalScore,
+ provisionalScore: _.isNil(attempt.provisionalScore)
+ ? existingAttempt.provisionalScore
+ : attempt.provisionalScore,
+ };
+ });
+
+ this.setState(prevState => ({
+ loadingMmSubmissionHistoryByMember: {
+ ...prevState.loadingMmSubmissionHistoryByMember,
+ [key]: false,
+ },
+ mmSubmissionHistoryByMember: {
+ ...prevState.mmSubmissionHistoryByMember,
+ [key]: historySubmissions,
+ },
+ }));
+ })
+ .catch(() => {
+ if (this.unmounted) {
+ return;
+ }
+ this.setState(prevState => ({
+ loadingMmSubmissionHistoryByMember: {
+ ...prevState.loadingMmSubmissionHistoryByMember,
+ [key]: false,
+ },
+ }));
+ });
+ }
+
+ /**
+ * Toggles a submission history modal and lazily loads MM history when needed.
+ * @param {String} historyKey Stable key for the submission row.
+ * @param {Object} submission Member-grouped submission row.
+ */
+ handleToggleSubmissionHistory(historyKey, submission) {
+ const { submissionHistoryOpen, toggleSubmissionHistory } = this.props;
+ const isOpening = !submissionHistoryOpen[historyKey];
+ toggleSubmissionHistory(historyKey);
+
+ if (!isOpening || !this.isMM()) {
+ return;
+ }
+
+ const loadedCount = _.get(submission, 'submissions.length', 0);
+ const expectedCount = Number(_.get(submission, 'submissionCount'));
+ if (Number.isFinite(expectedCount) && expectedCount > loadedCount) {
+ this.loadMmSubmissionHistory(submission);
+ }
+ }
+
/**
* Update sorted submission array
*/
@@ -844,6 +965,8 @@ class SubmissionsComponent extends React.Component {
downloadingAll,
completeSubmissions,
loadingCompleteSubmissionsForChallengeId,
+ loadingMmSubmissionHistoryByMember,
+ mmSubmissionHistoryByMember,
} = this.state;
const sortOptionClicked = {
@@ -1369,34 +1492,43 @@ class SubmissionsComponent extends React.Component {
}
{
isMM && (
- sortedSubmissions.map((submission, index) => (
- <SubmissionRow
- submissions={sortedSubmissions}
- showFinalResults={showFinalMmResults}
- isMM={isMM}
- isRDM={isRDM}
- key={submission.member}
- {...submission}
- challengeStatus={challenge.status}
- toggleHistory={() => { toggleSubmissionHistory(index); }}
- openHistory={(submissionHistoryOpen[index.toString()] || false)}
- isLoadingSubmissionInformation={isLoadingSubmissionInformation}
- submissionInformation={submissionInformation}
- onShowPopup={this.onHandleInformationPopup}
- getFlagFirstTry={this.getFlagFirstTry}
- onGetFlagImageFail={onGetFlagImageFail}
- submissionDetail={submission}
- viewAsTable={viewAsTable}
- numWinners={numWinners}
- auth={auth}
- isLoggedIn={isLoggedIn}
- />
- ))
+ sortedSubmissions.map((submission) => {
+ const historyKey = getMmSubmissionHistoryKey(submission);
+ const loadedHistory = mmSubmissionHistoryByMember[historyKey];
+ const rowSubmissions = loadedHistory || submission.submissions;
+ return (
+ <SubmissionRow
+ showFinalResults={showFinalMmResults}
+ isMM={isMM}
+ isRDM={isRDM}
+ key={historyKey || submission.member}
+ {...submission}
+ submissions={rowSubmissions}
+ submissionCount={submission.submissionCount}
+ challengeStatus={challenge.status}
+ toggleHistory={() => {
+ this.handleToggleSubmissionHistory(historyKey, submission);
+ }}
+ openHistory={(submissionHistoryOpen[historyKey] || false)}
+ loadingHistory={Boolean(loadingMmSubmissionHistoryByMember[historyKey])}
+ isLoadingSubmissionInformation={isLoadingSubmissionInformation}
+ submissionInformation={submissionInformation}
+ onShowPopup={this.onHandleInformationPopup}
+ getFlagFirstTry={this.getFlagFirstTry}
+ onGetFlagImageFail={onGetFlagImageFail}
+ submissionDetail={submission}
+ viewAsTable={viewAsTable}
+ numWinners={numWinners}
+ auth={auth}
+ isLoggedIn={isLoggedIn}
+ />
+ );
+ })
)
}
{
!isMM && (
- sortedSubmissions.map((memberGroup, index) => (
+ sortedSubmissions.map(memberGroup => (
<SubmissionRow
submissions={memberGroup.submissions}
showFinalResults={showFinalMmResults}
@@ -1406,8 +1538,8 @@ class SubmissionsComponent extends React.Component {
member={memberGroup.member}
rating={memberGroup.rating}
challengeStatus={challenge.status}
- toggleHistory={() => { toggleSubmissionHistory(index); }}
- openHistory={(submissionHistoryOpen[index.toString()] || false)}
+ toggleHistory={() => { toggleSubmissionHistory(memberGroup.member); }}
+ openHistory={(submissionHistoryOpen[memberGroup.member] || false)}
isLoadingSubmissionInformation={isLoadingSubmissionInformation}
submissionInformation={submissionInformation}
onShowPopup={this.onHandleInformationPopup}
diff --git a/src/shared/containers/challenge-detail/index.jsx b/src/shared/containers/challenge-detail/index.jsx
index 56653cb81..c153a5166 100644
--- a/src/shared/containers/challenge-detail/index.jsx
+++ b/src/shared/containers/challenge-detail/index.jsx
@@ -1592,6 +1592,7 @@ const mapDispatchToProps = (dispatch) => {
const {
includeMmSubmissions = true,
includeStatistics = includeMmSubmissions,
+ latestOnly = false,
} = options;
const challengeIdStr = _.toString(challengeId);
if (!challengeIdStr) {
@@ -1610,7 +1611,11 @@ const mapDispatchToProps = (dispatch) => {
}
const challengeSubmissionsPromise = includeMmSubmissions
- ? getChallengeSubmissionsService(tokenV3, challengeIdStr)
+ ? getChallengeSubmissionsService(
+ tokenV3,
+ challengeIdStr,
+ latestOnly ? { isLatest: true } : {},
+ )
: Promise.resolve({ data: [] });
Promise.all([
@@ -1858,8 +1863,8 @@ const mapDispatchToProps = (dispatch) => {
dispatch(a.updateChallengeInit(uuid));
dispatch(a.updateChallengeDone(uuid, challenge, tokenV3));
},
- loadMMSubmissions: (challengeId, tokenV3) => {
- dispatchReviewSummations(challengeId, tokenV3);
+ loadMMSubmissions: (challengeId, tokenV3, options = {}) => {
+ dispatchReviewSummations(challengeId, tokenV3, options);
},
getSubmissionArtifacts:
(submissionId, tokenV3) => getSubmissionArtifactsService(tokenV3, submissionId),
@@ -1894,7 +1899,7 @@ const mapDispatchToProps = (dispatch) => {
challengeId,
_.get(tokens, 'tokenV3'),
{
- includeMmSubmissions: isMMChallenge,
+ includeMmSubmissions: false,
includeStatistics: isMMChallenge,
},
);
diff --git a/src/shared/services/submissions.js b/src/shared/services/submissions.js
index 4ed829d44..dfd588899 100644
--- a/src/shared/services/submissions.js
+++ b/src/shared/services/submissions.js
@@ -30,10 +30,21 @@ async function fetchChallengeSubmissionsPage({
challengeId,
page,
perPage,
+ filters,
aggregated,
meta,
}) {
- const url = `${v6ApiUrl}/submissions?challengeId=${encodeURIComponent(challengeId)}&perPage=${perPage}&page=${page}`;
+ const params = new URLSearchParams();
+ params.set('challengeId', challengeId);
+ params.set('perPage', perPage);
+ params.set('page', page);
+ Object.keys(filters || {}).forEach((key) => {
+ const value = filters[key];
+ if (value !== undefined && value !== null && value !== '') {
+ params.set(key, value);
+ }
+ });
+ const url = `${v6ApiUrl}/submissions?${params.toString()}`;
const response = await fetch(url, {
method: 'GET',
headers: getHeaders(tokenV3),
@@ -65,6 +76,7 @@ async function fetchChallengeSubmissionsPage({
challengeId,
page: page + 1,
perPage,
+ filters,
aggregated: combined,
meta: latestMeta,
});
@@ -81,17 +93,27 @@ async function fetchChallengeSubmissionsPage({
* @param {String|Number} challengeId Challenge identifier used by the submissions API.
* @param {Object} options Optional pagination settings.
* @param {Number} options.perPage Number of records requested per API page.
+ * @param {Boolean} options.isLatest When true, fetch only the latest submission per member.
+ * @param {String|Number} options.memberId Optional member id used to fetch one member's history.
* @return {Promise<{data: Array, meta: Object}>} Aggregated submissions and
* final response metadata.
* @throws {Error} Throws when any submissions API page returns a non-2xx status.
*/
export async function getChallengeSubmissions(tokenV3, challengeId, options = {}) {
- const { perPage = DEFAULT_PER_PAGE } = options;
+ const {
+ isLatest,
+ memberId,
+ perPage = DEFAULT_PER_PAGE,
+ } = options;
const { data, meta } = await fetchChallengeSubmissionsPage({
tokenV3,
challengeId,
page: 1,
perPage,
+ filters: {
+ isLatest: isLatest === undefined ? undefined : isLatest,
+ memberId,
+ },
aggregated: [],
meta: null,
});
diff --git a/src/shared/utils/mm-review-summations.js b/src/shared/utils/mm-review-summations.js
index 5d5ba721f..b0a12e2db 100644
--- a/src/shared/utils/mm-review-summations.js
+++ b/src/shared/utils/mm-review-summations.js
@@ -178,6 +178,19 @@ function getSubmissionTimestamp(submission) {
return _.find(candidates, value => !!value) || null;
}
+/**
+ * Resolves the total number of attempts for a member from a submission row.
+ * Latest-only submission API responses include this value so the UI can show
+ * History counts without loading every historical attempt upfront.
+ *
+ * @param {Object} submission Raw submission returned by the submissions API.
+ * @returns {Number|null} Submission count, or null when unavailable.
+ */
+function getSubmissionCount(submission) {
+ const count = Number(_.get(submission, 'submissionCount'));
+ return Number.isFinite(count) ? count : null;
+}
+
function getSubmissionIdentifier(submission, index, handle) {
const rawSubmissionId = _.get(
submission,
@@ -596,18 +609,40 @@ export function buildMmSubmissionData(reviewSummations = [], rawSubmissions = []
}
const membersByHandle = new Map();
+ const latestRawSubmissionIds = new Set(
+ normalizedRawSubmissions
+ .filter(submission => submission && submission.isLatest === true)
+ .map(submission => _.toString(
+ _.get(submission, 'id', _.get(submission, 'submissionId', '')),
+ ))
+ .filter(id => id.length > 0),
+ );
+ const hasLatestRawSubmissions = latestRawSubmissionIds.size > 0;
normalizedReviewSummations.forEach((summation, index) => {
if (!summation) {
return;
}
+ const rawSubmissionId = _.get(
+ summation,
+ 'submissionId',
+ _.get(summation, 'id'),
+ );
+ if (
+ hasLatestRawSubmissions
+ && (!rawSubmissionId || !latestRawSubmissionIds.has(_.toString(rawSubmissionId)))
+ ) {
+ return;
+ }
+
const handle = getSummationHandle(summation);
if (!membersByHandle.has(handle)) {
membersByHandle.set(handle, {
handle,
memberId: null,
rating: null,
+ submissionCount: null,
submissionsMap: new Map(),
});
}
@@ -624,11 +659,6 @@ export function buildMmSubmissionData(reviewSummations = [], rawSubmissions = []
memberEntry.rating = rating;
}
- const rawSubmissionId = _.get(
- summation,
- 'submissionId',
- _.get(summation, 'id'),
- );
const submissionId = rawSubmissionId
? _.toString(rawSubmissionId)
: `unknown-${handle}-${index}`;
@@ -675,6 +705,7 @@ export function buildMmSubmissionData(reviewSummations = [], rawSubmissions = []
handle,
memberId: null,
rating: null,
+ submissionCount: null,
submissionsMap: new Map(),
});
}
@@ -690,6 +721,11 @@ export function buildMmSubmissionData(reviewSummations = [], rawSubmissions = []
memberEntry.rating = rating;
}
+ const submissionCount = getSubmissionCount(submission);
+ if (_.isNil(memberEntry.submissionCount) && !_.isNil(submissionCount)) {
+ memberEntry.submissionCount = submissionCount;
+ }
+
const submissionId = getSubmissionIdentifier(submission, index, handle);
const timestamp = getSubmissionTimestamp(submission);
const timestampValue = toTimestampValue(timestamp);
@@ -819,6 +855,9 @@ export function buildMmSubmissionData(reviewSummations = [], rawSubmissions = []
rating,
provisionalRank: null,
finalRank: null,
+ submissionCount: _.isNil(memberEntry.submissionCount)
+ ? submissionsWithProvisionalFallback.length
+ : memberEntry.submissionCount,
submissions: submissionsWithProvisionalFallback,
bestProvisionalScore,
bestProvisionalTimestamp,
--
2.43.0