Capping version chistory to 50

This commit is contained in:
Kasra Bigdeli
2019-04-04 22:14:59 -07:00
parent c6a0c167e8
commit b50c632d89
4 changed files with 70 additions and 0 deletions

View File

@@ -494,6 +494,12 @@ class AppsDataStore {
const self = this
return this.getAppDefinition(appName).then(function(app) {
// Drop older versions
app.versions = Utils.dropFirstElements(
app.versions,
CaptainConstants.configs.maxVersionHistory - 1
)
const versions = app.versions
let newVersionIndex = versions.length

View File

@@ -25,6 +25,8 @@ const configs = {
appLogSize: 500,
maxVersionHistory: 50,
skipVerifyingDomains: false,
registrySubDomainPort: 996,

View File

@@ -40,6 +40,15 @@ export default class Utils {
})
}
static dropFirstElements(arr: any[], maxLength: number) {
arr = arr || []
maxLength = Number(maxLength)
if (arr.length <= maxLength) return arr
return arr.slice(arr.length - maxLength)
}
static runPromises(
promises: (() => Promise<void>)[],
curr?: number

53
tests/utils.test..ts Normal file
View File

@@ -0,0 +1,53 @@
import Utils from '../src/utils/Utils'
test('Testing dropFirstElements - larger', () => {
const originalArray = []
for (let index = 0; index < 20; index++) {
originalArray.push('A' + index)
}
expect(Utils.dropFirstElements(originalArray, 2).join(',')) //
.toBe('A18,A19')
})
test('Testing dropFirstElements - same', () => {
const originalArray = []
for (let index = 0; index < 2; index++) {
originalArray.push('A' + index)
}
expect(Utils.dropFirstElements(originalArray, 2).join(',')) //
.toBe('A0,A1')
})
test('Testing dropFirstElements - smaller', () => {
const originalArray = []
for (let index = 0; index < 2; index++) {
originalArray.push('A' + index)
}
expect(Utils.dropFirstElements(originalArray, 3).join(',')) //
.toBe('A0,A1')
})
test('Testing dropFirstElements - smaller (1)', () => {
const originalArray = []
for (let index = 0; index < 1; index++) {
originalArray.push('A' + index)
}
expect(Utils.dropFirstElements(originalArray, 3).join(',')) //
.toBe('A0')
})
test('Testing dropFirstElements - smaller (0)', () => {
const originalArray = []
for (let index = 0; index < 0; index++) {
originalArray.push('A' + index)
}
expect(Utils.dropFirstElements(originalArray, 3).join(',')) //
.toBe('')
})