Skip to content

Commit 4e7070b

Browse files
committed
Fetch latest release from github only once a day
1 parent a45ffff commit 4e7070b

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

ui/src/components/page/GlobalFooter.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
</div>
2323
<div class="line" v-if="$store.getters.userInfo.roletype === 'Admin'">
2424
CloudStack {{ $store.getters.features.cloudstackversion }}
25-
<span v-if="$store.getters.features.cloudstackversion && $store.getters.features.cloudstackversion.split('-')[0] !== $store.getters.latestVersion && $store.getters.latestVersion !== ''">
25+
<span v-if="$store.getters.features.cloudstackversion && $store.getters?.latestVersion?.version && $store.getters.features.cloudstackversion.split('-')[0] !== $store.getters.latestVersion.version">
2626
<a-divider type="vertical" />
2727
<a
28-
:href="'https://github.com/apache/cloudstack/releases/tag/' + $store.getters.latestVersion"
28+
:href="'https://github.com/apache/cloudstack/releases/tag/' + $store.getters.latestVersion.version"
2929
target="_blank">
3030
<info-circle-outlined />
31-
{{ $t('label.new.version.available') + ': ' + $store.getters.latestVersion }}
31+
{{ $t('label.new.version.available') + ': ' + $store.getters.latestVersion.version }}
3232
</a>
3333
</span>
3434
<a-divider type="vertical" />

ui/src/store/modules/user.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
HEADER_NOTICES,
3838
DOMAIN_STORE,
3939
DARK_MODE,
40+
LATEST_CS_VERSION,
4041
CUSTOM_COLUMNS
4142
} from '@/store/mutation-types'
4243

@@ -154,6 +155,7 @@ const user = {
154155
state.loginFlag = flag
155156
},
156157
SET_LATEST_VERSION: (state, version) => {
158+
vueProps.$localStorage.set(LATEST_CS_VERSION, version)
157159
state.latestVersion = version
158160
}
159161
},
@@ -200,7 +202,8 @@ const user = {
200202
commit('SET_2FA_PROVIDER', result.providerfor2fa)
201203
commit('SET_2FA_ISSUER', result.issuerfor2fa)
202204
commit('SET_LOGIN_FLAG', false)
203-
commit('SET_LATEST_VERSION', '')
205+
const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION, { version: '', fetchedTs: 0 })
206+
commit('SET_LATEST_VERSION', latestVersion)
204207
notification.destroy()
205208

206209
resolve()
@@ -219,10 +222,12 @@ const user = {
219222
const cachedCustomColumns = vueProps.$localStorage.get(CUSTOM_COLUMNS, {})
220223
const domainStore = vueProps.$localStorage.get(DOMAIN_STORE, {})
221224
const darkMode = vueProps.$localStorage.get(DARK_MODE, false)
225+
const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION, { version: '', fetchedTs: 0 })
222226
const hasAuth = Object.keys(cachedApis).length > 0
223227

224228
commit('SET_DOMAIN_STORE', domainStore)
225229
commit('SET_DARK_MODE', darkMode)
230+
commit('SET_LATEST_VERSION', latestVersion)
226231
if (hasAuth) {
227232
console.log('Login detected, using cached APIs')
228233
commit('SET_ZONES', cachedZones)
@@ -236,20 +241,7 @@ const user = {
236241
const result = response.listusersresponse.user[0]
237242
commit('SET_INFO', result)
238243
commit('SET_NAME', result.firstname + ' ' + result.lastname)
239-
if (result.rolename === 'Root Admin') {
240-
axios.get(
241-
'https://api.github.com/repos/apache/cloudstack/releases'
242-
).then(response => {
243-
for (const release of response) {
244-
if (release.tag_name.toLowerCase().includes('rc')) {
245-
continue
246-
} else {
247-
commit('SET_LATEST_VERSION', release.tag_name)
248-
break
249-
}
250-
}
251-
}).catch(ignored => {})
252-
}
244+
store.dispatch('SetCsLatestVersion', result.rolename)
253245
resolve(cachedApis)
254246
}).catch(error => {
255247
reject(error)
@@ -327,6 +319,7 @@ const user = {
327319
const result = response.listusersresponse.user[0]
328320
commit('SET_INFO', result)
329321
commit('SET_NAME', result.firstname + ' ' + result.lastname)
322+
store.dispatch('SetCsLatestVersion', result.rolename)
330323
}).catch(error => {
331324
reject(error)
332325
})
@@ -461,6 +454,22 @@ const user = {
461454
SetDomainStore ({ commit }, domainStore) {
462455
commit('SET_DOMAIN_STORE', domainStore)
463456
},
457+
SetCsLatestVersion ({ commit }, rolename) {
458+
if (rolename === 'Root Admin' && (+new Date() - store.getters.latestVersion.fetchedTs) > 24 * 60 * 60 * 1000) {
459+
axios.get(
460+
'https://api.github.com/repos/apache/cloudstack/releases'
461+
).then(response => {
462+
for (const release of response) {
463+
if (release.tag_name.toLowerCase().includes('rc')) {
464+
continue
465+
} else {
466+
commit('SET_LATEST_VERSION', { version: release.tag_name, fetchedTs: (+new Date()) })
467+
break
468+
}
469+
}
470+
}).catch(ignored => {})
471+
}
472+
},
464473
SetDarkMode ({ commit }, darkMode) {
465474
commit('SET_DARK_MODE', darkMode)
466475
},

ui/src/store/mutation-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const USE_BROWSER_TIMEZONE = 'USE_BROWSER_TIMEZONE'
3535
export const SERVER_MANAGER = 'SERVER_MANAGER'
3636
export const DOMAIN_STORE = 'DOMAIN_STORE'
3737
export const DARK_MODE = 'DARK_MODE'
38+
export const LATEST_CS_VERSION = 'LATEST_CS_VERSION'
3839
export const VUE_VERSION = 'VUE_VERSION'
3940
export const CUSTOM_COLUMNS = 'CUSTOM_COLUMNS'
4041

0 commit comments

Comments
 (0)