fix sorting of commit groups by not using map for storing arrays

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-01-16 14:03:11 +01:00
parent 2c8f9deb05
commit d4bf176d9f
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
2 changed files with 16 additions and 11 deletions

View File

@ -40,14 +40,19 @@ class Builds {
/* This sorts so that builds are shown grouped by commit,
* but still in chronological order based on $loki. */
sortBuildsByCommit (builds) {
let bc = {}, b
let map = {}
let bc = [], b
/* put builds under commit keys */
for (let i=0; i<builds.length; i++) {
b = builds[i]
bc[b.commit] || (bc[b.commit] = [])
bc[b.commit].push(b)
if (map[b.commit] !== undefined) {
bc[map[b.commit]].push(b)
} else {
bc.push([b])
map[b.commit] = bc.length-1
}
}
bc = Object.values(bc)
/* compare commits by their lowest $loki index */
bc.sort((o1, o2) => {
let o1_min = Math.min(o1.map((o) => o.$loki))
let o2_min = Math.min(o2.map((o) => o.$loki))

View File

@ -51,13 +51,13 @@ describe('Builds', () => {
return build
})
expect(rval).to.deep.equal([
{id: '#1', commit: 'abcd1234', platform: 'macos'},
{id: '#1', commit: 'abcd1234', platform: 'linux'},
{id: '#1', commit: 'abcd1234', platform: 'windows'},
{id: '#2', commit: 'abcd1234', platform: 'linux'},
{id: '#2', commit: '1234abcd', platform: 'macos'},
{id: '#2', commit: '1234abcd', platform: 'windows'},
{id: '#3', commit: '1234abcd', platform: 'linux'}
{ id: '#1', commit: 'abcd1234', platform: 'macos' },
{ id: '#1', commit: 'abcd1234', platform: 'linux' },
{ id: '#1', commit: 'abcd1234', platform: 'windows' },
{ id: '#2', commit: 'abcd1234', platform: 'linux' },
{ id: '#2', commit: '1234abcd', platform: 'macos' },
{ id: '#2', commit: '1234abcd', platform: 'windows' },
{ id: '#3', commit: '1234abcd', platform: 'linux' }
])
})
})