Skip to content

Commit 8060abd

Browse files
committed
Fetch latest release from github only once a day
1 parent 686b387 commit 8060abd

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
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: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import {
3939
DARK_MODE,
4040
CUSTOM_COLUMNS,
4141
OAUTH_DOMAIN,
42-
OAUTH_PROVIDER
42+
OAUTH_PROVIDER,
43+
LATEST_CS_VERSION
4344
} from '@/store/mutation-types'
4445

4546
const user = {
@@ -170,6 +171,7 @@ const user = {
170171
vueProps.$localStorage.set(OAUTH_PROVIDER, provider)
171172
},
172173
SET_LATEST_VERSION: (state, version) => {
174+
vueProps.$localStorage.set(LATEST_CS_VERSION, version)
173175
state.latestVersion = version
174176
}
175177
},
@@ -216,7 +218,8 @@ const user = {
216218
commit('SET_2FA_PROVIDER', result.providerfor2fa)
217219
commit('SET_2FA_ISSUER', result.issuerfor2fa)
218220
commit('SET_LOGIN_FLAG', false)
219-
commit('SET_LATEST_VERSION', '')
221+
const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION, { version: '', fetchedTs: 0 })
222+
commit('SET_LATEST_VERSION', latestVersion)
220223
notification.destroy()
221224

222225
resolve()
@@ -282,10 +285,12 @@ const user = {
282285
const cachedCustomColumns = vueProps.$localStorage.get(CUSTOM_COLUMNS, {})
283286
const domainStore = vueProps.$localStorage.get(DOMAIN_STORE, {})
284287
const darkMode = vueProps.$localStorage.get(DARK_MODE, false)
288+
const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION, { version: '', fetchedTs: 0 })
285289
const hasAuth = Object.keys(cachedApis).length > 0
286290

287291
commit('SET_DOMAIN_STORE', domainStore)
288292
commit('SET_DARK_MODE', darkMode)
293+
commit('SET_LATEST_VERSION', latestVersion)
289294
if (hasAuth) {
290295
console.log('Login detected, using cached APIs')
291296
commit('SET_ZONES', cachedZones)
@@ -299,20 +304,7 @@ const user = {
299304
const result = response.listusersresponse.user[0]
300305
commit('SET_INFO', result)
301306
commit('SET_NAME', result.firstname + ' ' + result.lastname)
302-
if (result.rolename === 'Root Admin') {
303-
axios.get(
304-
'https://api.github.com/repos/apache/cloudstack/releases'
305-
).then(response => {
306-
for (const release of response) {
307-
if (release.tag_name.toLowerCase().includes('rc')) {
308-
continue
309-
} else {
310-
commit('SET_LATEST_VERSION', release.tag_name)
311-
break
312-
}
313-
}
314-
}).catch(ignored => {})
315-
}
307+
store.dispatch('SetCsLatestVersion', result.rolename)
316308
resolve(cachedApis)
317309
}).catch(error => {
318310
reject(error)
@@ -393,6 +385,7 @@ const user = {
393385
const result = response.listusersresponse.user[0]
394386
commit('SET_INFO', result)
395387
commit('SET_NAME', result.firstname + ' ' + result.lastname)
388+
store.dispatch('SetCsLatestVersion', result.rolename)
396389
}).catch(error => {
397390
reject(error)
398391
})
@@ -543,6 +536,22 @@ const user = {
543536
SetDomainStore ({ commit }, domainStore) {
544537
commit('SET_DOMAIN_STORE', domainStore)
545538
},
539+
SetCsLatestVersion ({ commit }, rolename) {
540+
if (rolename === 'Root Admin' && (+new Date() - store.getters.latestVersion.fetchedTs) > 24 * 60 * 60 * 1000) {
541+
axios.get(
542+
'https://api.github.com/repos/apache/cloudstack/releases'
543+
).then(response => {
544+
for (const release of response) {
545+
if (release.tag_name.toLowerCase().includes('rc')) {
546+
continue
547+
} else {
548+
commit('SET_LATEST_VERSION', { version: release.tag_name, fetchedTs: (+new Date()) })
549+
break
550+
}
551+
}
552+
}).catch(ignored => {})
553+
}
554+
},
546555
SetDarkMode ({ commit }, darkMode) {
547556
commit('SET_DARK_MODE', darkMode)
548557
},

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
export const RELOAD_ALL_PROJECTS = 'RELOAD_ALL_PROJECTS'

0 commit comments

Comments
 (0)