Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix long initial time with huge print history #1714

Merged
merged 7 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 59 additions & 58 deletions src/components/panels/HistoryListPanel.vue

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion src/components/panels/HistoryStatisticsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@
{{ $t('History.Table') }}
</v-btn>
</v-btn-toggle>
<v-tooltip v-if="!allLoaded" top>
<template #activator="{ on, attrs }">
<v-btn
outlined
small
:loading="loadings.includes('historyLoadAll')"
class="ml-3 minwidth-0 px-2"
color="primary"
v-bind="attrs"
v-on="on"
@click="refreshHistory">
<v-icon small>{{ mdiDatabaseArrowDownOutline }}</v-icon>
</v-btn>
</template>
<span>{{ $t('History.LoadCompleteHistory') }}</span>
</v-tooltip>
</div>
</v-col>
<v-col class="col-12 col-sm-12 col-md-4">
Expand Down Expand Up @@ -98,12 +114,13 @@ import HistoryFilamentUsage from '@/components/charts/HistoryFilamentUsage.vue'
import HistoryPrinttimeAvg from '@/components/charts/HistoryPrinttimeAvg.vue'
import HistoryAllPrintStatusChart from '@/components/charts/HistoryAllPrintStatusChart.vue'
import { ServerHistoryStateJob } from '@/store/server/history/types'
import { mdiChartAreaspline } from '@mdi/js'
import { mdiChartAreaspline, mdiDatabaseArrowDownOutline } from '@mdi/js'
@Component({
components: { Panel, HistoryFilamentUsage, HistoryPrinttimeAvg, HistoryAllPrintStatusChart },
})
export default class HistoryStatisticsPanel extends Mixins(BaseMixin) {
mdiChartAreaspline = mdiChartAreaspline
mdiDatabaseArrowDownOutline = mdiDatabaseArrowDownOutline

get selectedJobs() {
return this.$store.state.gui.view.history.selectedJobs ?? []
Expand Down Expand Up @@ -197,6 +214,16 @@ export default class HistoryStatisticsPanel extends Mixins(BaseMixin) {
this.$store.dispatch('gui/saveSetting', { name: 'view.history.toggleChartCol2', value: newVal })
}

get allLoaded() {
return this.$store.state.server.history.all_loaded ?? false
}

refreshHistory() {
this.$store.dispatch('socket/addLoading', { name: 'historyLoadAll' })

this.$socket.emit('server.history.list', { start: 0, limit: 50 }, { action: 'server/history/getHistory' })
}

formatPrintTime(totalSeconds: number) {
if (totalSeconds) {
let output = ''
Expand Down
3 changes: 1 addition & 2 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
"Jobs": "Drucke",
"LastModified": "Zuletzt geändert",
"LayerHeight": "Schichthöhe",
"LoadCompleteHistory": "Lade vollständige Historie",
"LongestPrinttime": "Druckzeit - längste",
"Note": "Notiz",
"ObjectHeight": "Objekthöhe",
Expand Down Expand Up @@ -381,8 +382,6 @@
},
"Table": "Tabelle",
"TitleExportHistory": "Historie exportieren",
"TitleRefreshHistory": "Historie aktualisieren",
"TitleSettings": "Einstellungen",
"TotalDuration": "Gesamtdauer",
"TotalFilamentUsed": "Filament verwendet - gesamt",
"TotalJobs": "Druckvorgänge - gesamt",
Expand Down
3 changes: 1 addition & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
"Jobs": "Jobs",
"LastModified": "Last Modified",
"LayerHeight": "Layer Height",
"LoadCompleteHistory": "Load complete history",
"LongestPrinttime": "Longest Print Time",
"Note": "Note",
"ObjectHeight": "Object Height",
Expand Down Expand Up @@ -381,8 +382,6 @@
},
"Table": "Table",
"TitleExportHistory": "Export History",
"TitleRefreshHistory": "Refresh History",
"TitleSettings": "Settings",
"TotalDuration": "Total Time",
"TotalFilamentUsed": "Total Filament Used",
"TotalJobs": "Total Jobs",
Expand Down
6 changes: 2 additions & 4 deletions src/pages/History.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<style scoped></style>

<template>
<div>
<v-row>
<v-col>
<history-statistics-panel></history-statistics-panel>
<history-statistics-panel />
</v-col>
</v-row>
<v-row class="mt-0">
<v-col>
<history-list-panel></history-list-panel>
<history-list-panel />
</v-col>
</v-row>
</div>
Expand Down
32 changes: 25 additions & 7 deletions src/store/server/history/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const actions: ActionTree<ServerHistoryState, RootState> = {
},

init() {
Vue.$socket.emit('server.history.list', { start: 0, limit: 50 }, { action: 'server/history/getHistory' })
Vue.$socket.emit(
'server.history.list',
{ start: 0, limit: 50, max: 100 },
{ action: 'server/history/getHistory' }
)
Vue.$socket.emit('server.history.totals', {}, { action: 'server/history/getTotals' })
},

Expand All @@ -18,23 +22,37 @@ export const actions: ActionTree<ServerHistoryState, RootState> = {
},

async getHistory({ commit, dispatch, state }, payload) {
if ('requestParams' in payload && 'start' in payload.requestParams && payload.requestParams.start === 0)
await commit('resetJobs')
if ('requestParams' in payload && (payload.requestParams?.start ?? 0) === 0) commit('resetJobs')

payload.jobs?.forEach((job: ServerHistoryStateJob) => {
if (state.jobs.findIndex((stateJob) => stateJob.job_id === job.job_id) === -1) commit('addJob', job)
})

if (payload.requestParams?.limit > 0 && payload.jobs?.length === payload.requestParams.limit)
const start = payload.requestParams?.start ?? 0
const limit = payload.requestParams?.limit ?? 50
const max = payload.requestParams?.max ?? null

if (limit > 0 && (max === null || max > start + limit) && payload.jobs?.length === limit) {
Vue.$socket.emit(
'server.history.list',
{
start: payload.requestParams.start + payload.requestParams.limit,
limit: payload.requestParams.limit,
start: start + limit,
limit: limit,
max: max,
},
{ action: 'server/history/getHistory' }
)
else await dispatch('loadHistoryNotes')

// stop here until all pulls are done
return
}

if (payload.jobs?.length < limit) {
dispatch('socket/removeLoading', { name: 'historyLoadAll' }, { root: true })
commit('setAllLoaded')
}

dispatch('loadHistoryNotes')
},

loadHistoryNotes({ dispatch, rootState }) {
Expand Down
1 change: 1 addition & 0 deletions src/store/server/history/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const getDefaultState = (): ServerHistoryState => {
longest_job: 0,
longest_print: 0,
},
all_loaded: false,
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/store/server/history/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export const mutations: MutationTree<ServerHistoryState> = {
const index = state.jobs.findIndex((job) => job.job_id === payload)
if (index !== -1) state.jobs.splice(index, 1)
},

setAllLoaded(state) {
Vue.set(state, 'all_loaded', true)
},
}
1 change: 1 addition & 0 deletions src/store/server/history/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ServerHistoryState {
longest_job: number
longest_print: number
}
all_loaded: boolean
}

export interface ServerHistoryStateJob {
Expand Down
Loading