mirror of
https://github.com/caprover/caprover
synced 2025-10-30 18:07:25 +00:00
Capping version chistory to 50
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -25,6 +25,8 @@ const configs = {
|
||||
|
||||
appLogSize: 500,
|
||||
|
||||
maxVersionHistory: 50,
|
||||
|
||||
skipVerifyingDomains: false,
|
||||
|
||||
registrySubDomainPort: 996,
|
||||
|
||||
@@ -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
53
tests/utils.test..ts
Normal 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('')
|
||||
})
|
||||
Reference in New Issue
Block a user