Skip to content

Commit

Permalink
fix(FileSystem): metadata load improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Feb 25, 2025
1 parent abc0ba9 commit 7e3442a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
14 changes: 6 additions & 8 deletions src/components/widgets/spoolman/SpoolSelectionDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,13 @@ export default class SpoolSelectionDialog extends Mixins(StateMixin, BrowserMixi
}
if (this.currentFileName) {
// prefetch file metadata
if (!this.currentFile && this.currentFileName.includes('/')) {
// if the file is in a subdirectory and isn't cached
// we need to populate the cache
const { rootPath } = getFilePaths(this.currentFileName, 'gcodes')
const { rootPath } = getFilePaths(this.currentFileName, 'gcodes')
const directoryLoaded = rootPath in this.$store.state.files.pathFiles
// Load the containing the currently printing file if we haven't done that already
if (!directoryLoaded) {
SocketActions.serverFilesGetDirectory(rootPath)
} else {
// otherwise just refresh the corresponding file
SocketActions.serverFilesMetadata(this.currentFileName)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/store/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ export const handleCurrentFileChange = (payload: KlipperPrinterState, state: Roo
payload.print_stats?.filename &&
payload.print_stats.filename !== state.printer.printer.print_stats?.filename
) {
const paths = getFilePaths(payload.print_stats.filename, 'gcodes')
const { rootPath } = getFilePaths(payload.print_stats.filename, 'gcodes')

const directoryLoaded = paths.rootPath in state.files.pathFiles
const directoryLoaded = rootPath in state.files.pathFiles

// Load the folder containing the currently printing file if we haven't done that already
if (!directoryLoaded) {
SocketActions.serverFilesGetDirectory(paths.rootPath)
SocketActions.serverFilesGetDirectory(rootPath)
}
}
}
30 changes: 24 additions & 6 deletions src/store/history/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { HistoryItem, HistoryState } from './types'
import type { RootState } from '../types'
import { SocketActions } from '@/api/socketActions'
import { Globals } from '@/globals'
import getFilePaths from '@/util/get-file-paths'

export const actions: ActionTree<HistoryState, RootState> = {
/**
Expand Down Expand Up @@ -56,13 +57,30 @@ export const actions: ActionTree<HistoryState, RootState> = {
/**
* History has changed, update the data.
*/
async onHistoryChange ({ commit }, payload: { action: string; job: HistoryItem }) {
async onHistoryChange ({ commit, rootState }, payload: { action: 'added' | 'finished'; job: HistoryItem }) {
SocketActions.serverHistoryTotals()
if (
payload
) {
if (payload.action === 'added') commit('setAddHistory', payload.job)
if (payload.action === 'finished') commit('setUpdateHistory', payload.job)

if (payload) {
switch (payload.action) {
case 'added': {
commit('setAddHistory', payload.job)

const { rootPath } = getFilePaths(payload.job.filename, 'gcodes')

const directoryLoaded = rootPath in rootState.files.pathFiles

// If the folder containing the file has been loaded, update the file metadata
if (directoryLoaded) {
SocketActions.serverFilesMetadata(payload.job.filename)
}

break
}
case 'finished':
commit('setUpdateHistory', payload.job)

break
}
}
},

Expand Down
12 changes: 9 additions & 3 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export const getters: GetterTree<PrinterState, RootState> = {
const printerFilename = state.printer.print_stats?.filename

if (printerFilename) {
const paths = getFilePaths(printerFilename, 'gcodes')
const { rootPath, filename } = getFilePaths(printerFilename, 'gcodes')

const printerFile: AppFileWithMeta | undefined = rootGetters['files/getFile'](paths.rootPath, paths.filename)
const printerFile: AppFileWithMeta | undefined = rootGetters['files/getFile'](rootPath, filename)

return printerFile
}
Expand Down Expand Up @@ -168,10 +168,16 @@ export const getters: GetterTree<PrinterState, RootState> = {
},

getPrintProgress: (state, getters, rootState): number => {
const printerFile: AppFileWithMeta | undefined = getters.getPrinterFile

if (printerFile?.history?.status === 'completed') {
return 1
}

const printProgressCalculation = rootState.config.uiSettings.general.printProgressCalculation

const printProgressCalculationResults = printProgressCalculation
.map(type => {
.map((type): number => {
switch (type) {
case 'file':
return getters.getFileRelativePrintProgress
Expand Down

0 comments on commit 7e3442a

Please sign in to comment.