Skip to content

Commit c8b5332

Browse files
committed
Fix for wrong counts on history on profile
1 parent 91273ac commit c8b5332

2 files changed

Lines changed: 16 additions & 25 deletions

File tree

src/services/StatisticsService.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,32 +1811,25 @@ function dedupeUnifiedHistoryRows (rows) {
18111811
}
18121812

18131813
/**
1814-
* Remove empty imported Marathon Match rows that still reference unmapped numeric
1814+
* Remove imported Marathon Match rows that still reference unmapped numeric
18151815
* legacy challenge ids.
18161816
*
1817-
* Older Marathon Match histories can predate challenge-api metadata while still
1818-
* carrying rating, placement, or percentile data from the members schema. Those
1819-
* rows are part of the member's rating timeline and must remain visible even
1820-
* when a challenge title cannot be resolved.
1817+
* Resolved legacy ids are canonicalized before this point. Any remaining
1818+
* numeric MM challenge id cannot be matched to challenge-api metadata, so it is
1819+
* ignored to avoid surfacing stale legacy rating rows or double-counting history.
18211820
*
18221821
* @param {Array<Object>} rows persisted and/or transient history rows
1823-
* @returns {Array<Object>} history rows without empty unresolved legacy MM entries
1822+
* @returns {Array<Object>} history rows without unresolved legacy MM entries
18241823
*/
1825-
function filterEmptyUnresolvedLegacyMarathonHistoryRows (rows) {
1824+
function filterUnresolvedLegacyMarathonHistoryRows (rows) {
18261825
return _.filter(rows || [], (row) => {
18271826
const challengeId = normalizeChallengeLookupKey(row && row.challengeId)
18281827
const isLegacyNumericChallenge = challengeId && /^\d+$/.test(challengeId)
18291828
const isMarathonHistory = row &&
18301829
row.trackName === TRACK_NAMES.DATA_SCIENCE &&
18311830
row.typeName === TYPE_NAMES.MARATHON_MATCH
1832-
const hasHistoryData = !_.isNil(row.newRating) ||
1833-
!_.isNil(row.oldRating) ||
1834-
!_.isNil(row.placement) ||
1835-
!_.isNil(row.percentile) ||
1836-
!_.isNil(row.newVolatility) ||
1837-
!_.isNil(row.oldVolatility)
1838-
1839-
return !(isMarathonHistory && isLegacyNumericChallenge && !row.challengeName && !hasHistoryData)
1831+
1832+
return !(isMarathonHistory && isLegacyNumericChallenge && !row.challengeName)
18401833
})
18411834
}
18421835

@@ -2713,7 +2706,7 @@ async function getHistoryStats (currentUser, handle, query) {
27132706
unresolvedPairKeys = getUnresolvedHistoryPairKeys(unresolvedPairKeys, legacyCodeFallbackRows)
27142707
}
27152708

2716-
annotatedRows = filterEmptyUnresolvedLegacyMarathonHistoryRows(annotatedRows)
2709+
annotatedRows = filterUnresolvedLegacyMarathonHistoryRows(annotatedRows)
27172710

27182711
const orderedRows = orderUnifiedHistoryRows(recomputeUnifiedHistoryMostRecentFlags(annotatedRows))
27192712
if (orderedRows.length > 0) {

test/unit/StatisticsService.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,10 +1542,9 @@ describe('statistics service unit tests', () => {
15421542
}
15431543
})
15441544

1545-
it('getHistoryStats should preserve data-bearing unresolved legacy numeric Marathon Match rows', async () => {
1545+
it('getHistoryStats should drop unresolved legacy numeric Marathon Match rows', async () => {
15461546
const ratingDate = new Date('2025-08-27T17:05:00.000Z')
15471547
const legacyDate = new Date('2014-04-18T00:00:00.000Z')
1548-
const emptyLegacyDate = new Date('2013-04-18T00:00:00.000Z')
15491548
const challenge = {
15501549
id: 'mm-challenge-uuid',
15511550
legacyId: null,
@@ -1578,10 +1577,11 @@ describe('statistics service unit tests', () => {
15781577
newRating: 2946,
15791578
mostRecent: true
15801579
}, {
1581-
trackId: 'track-ds-id',
1580+
trackId: 'track-dev-id',
15821581
typeId: 'type-mm-id',
1583-
challengeId: '15949',
1584-
eventDate: emptyLegacyDate,
1582+
challengeId: 'mm-challenge-uuid',
1583+
challengeName: 'Marathon Match 163',
1584+
eventDate: ratingDate,
15851585
mostRecent: false
15861586
}, {
15871587
trackId: 'track-ds-id',
@@ -1605,13 +1605,11 @@ describe('statistics service unit tests', () => {
16051605

16061606
result.should.have.length(1)
16071607
should.exist(result[0].DATA_SCIENCE)
1608-
result[0].DATA_SCIENCE.MARATHON_MATCH.history.should.have.length(2)
1608+
result[0].DATA_SCIENCE.MARATHON_MATCH.history.should.have.length(1)
16091609
result[0].DATA_SCIENCE.MARATHON_MATCH.history[0].challengeId.should.equal('mm-challenge-uuid')
16101610
result[0].DATA_SCIENCE.MARATHON_MATCH.history[0].challengeName.should.equal('Marathon Match 163')
1611+
result[0].DATA_SCIENCE.MARATHON_MATCH.history[0].rating.should.equal(2739)
16111612
result[0].DATA_SCIENCE.MARATHON_MATCH.history[0].mostRecent.should.equal(true)
1612-
result[0].DATA_SCIENCE.MARATHON_MATCH.history[1].challengeId.should.equal(15948)
1613-
result[0].DATA_SCIENCE.MARATHON_MATCH.history[1].rating.should.equal(2946)
1614-
result[0].DATA_SCIENCE.MARATHON_MATCH.history[1].mostRecent.should.equal(false)
16151613
} finally {
16161614
restore()
16171615
}

0 commit comments

Comments
 (0)