Skip to content

Commit

Permalink
perf(webui): load metrics with promises instead of await
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Jul 12, 2023
1 parent 5438444 commit 66dd1c2
Showing 1 changed file with 67 additions and 21 deletions.
88 changes: 67 additions & 21 deletions komga-webui/src/views/Metrics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,74 @@ export default Vue.extend({
},
methods: {
async loadData() {
this.tasks = await this.$komgaMetrics.getMetric('komga.tasks.execution')
this.tasksCount = await this.getStatisticForEachTagValue(this.tasks, 'type', 'COUNT')
this.tasksTotalTime = await this.getStatisticForEachTagValue(this.tasks, 'type', 'TOTAL_TIME')
this.series = await this.$komgaMetrics.getMetric('komga.series')
this.seriesAllTags = await this.getStatisticForEachTagValue(this.series, 'library')
this.books = await this.$komgaMetrics.getMetric('komga.books')
this.booksAllTags = await this.getStatisticForEachTagValue(this.books, 'library')
this.booksFileSize = await this.$komgaMetrics.getMetric('komga.books.filesize')
this.fileSizeAllTags = await this.getStatisticForEachTagValue(this.booksFileSize, 'library')
this.sidecars = await this.$komgaMetrics.getMetric('komga.sidecars')
this.sidecarsAllTags = await this.getStatisticForEachTagValue(this.sidecars, 'library')
this.collections = await this.$komgaMetrics.getMetric('komga.collections')
this.readlists = await this.$komgaMetrics.getMetric('komga.readlists')
this.$komgaMetrics.getMetric('komga.tasks.execution')
.then(m => {
this.tasks = m
this.getStatisticForEachTagValue(m, 'type', 'COUNT')
.then(m => this.tasksCount = m)
.catch(() => {
})
this.getStatisticForEachTagValue(m, 'type', 'TOTAL_TIME')
.then(m => this.tasksTotalTime = m)
.catch(() => {
})
})
.catch(() => {
})
this.$komgaMetrics.getMetric('komga.series')
.then(m => {
this.series = m
this.getStatisticForEachTagValue(m, 'library')
.then(v => this.seriesAllTags = v)
},
)
.catch(() => {
})
this.$komgaMetrics.getMetric('komga.books')
.then(m => {
this.books = m
this.getStatisticForEachTagValue(m, 'library')
.then(v => this.booksAllTags = v)
},
)
.catch(() => {
})
this.$komgaMetrics.getMetric('komga.books.filesize')
.then(m => {
this.booksFileSize = m
this.getStatisticForEachTagValue(m, 'library')
.then(v => this.fileSizeAllTags = v)
},
)
.catch(() => {
})
this.$komgaMetrics.getMetric('komga.sidecars')
.then(m => {
this.sidecars = m
this.getStatisticForEachTagValue(m, 'library')
.then(v => this.sidecarsAllTags = v)
},
)
.catch(() => {
})
this.$komgaMetrics.getMetric('komga.collections')
.then(m => this.collections = m)
.catch(() => {
})
this.$komgaMetrics.getMetric('komga.readlists')
.then(m => this.readlists = m)
.catch(() => {
})
},
async getStatisticForEachTagValue(metric: MetricDto, tag: string, statistic: string = 'VALUE'): Promise<{ [key: string]: number | undefined } | undefined> {
async getStatisticForEachTagValue(metric: MetricDto, tag: string, statistic: string = 'VALUE'): Promise<{
[key: string]: number | undefined
} | undefined> {
const tagDto = metric.availableTags.find(x => x.tag === tag)
if (tagDto) {
const tagToStatistic = tagDto.values.reduce((a, b) => {
Expand Down

0 comments on commit 66dd1c2

Please sign in to comment.