chore: add upload timing logs

This commit is contained in:
Tom Boullay
2026-04-27 23:11:16 +02:00
parent 5556364601
commit 799e61c92e
+99 -17
View File
@@ -10,6 +10,30 @@ import type { FileDiff } from '@/lib/types'
import { checkFolderDiffs, stageUpload, uploadDrive, uploadGit } from '@/lib/upload-api' import { checkFolderDiffs, stageUpload, uploadDrive, uploadGit } from '@/lib/upload-api'
import type { CheckResult } from '@/lib/upload-api' import type { CheckResult } from '@/lib/upload-api'
const UPLOAD_LOG_PREFIX = '[upload-gltf]'
function formatElapsed(startedAt: number) {
return `${((performance.now() - startedAt) / 1000).toFixed(1)}s`
}
function startTimedLog(label: string, details?: Record<string, unknown>) {
const startedAt = performance.now()
console.info(`${UPLOAD_LOG_PREFIX} ${label} started`, details || '')
const interval = window.setInterval(() => {
console.info(`${UPLOAD_LOG_PREFIX} ${label} still running`, { elapsed: formatElapsed(startedAt), ...details })
}, 10_000)
return (status: 'done' | 'failed' | 'cancelled' = 'done', extra?: Record<string, unknown>) => {
window.clearInterval(interval)
console.info(`${UPLOAD_LOG_PREFIX} ${label} ${status}`, {
elapsed: formatElapsed(startedAt),
...details,
...extra,
})
}
}
interface UseUploadOrchestratorParams { interface UseUploadOrchestratorParams {
secret: string secret: string
setSecretError: (err: string | null) => void setSecretError: (err: string | null) => void
@@ -58,12 +82,24 @@ export function useUploadOrchestrator({
return return
} }
const gitResult = await uploadGit( const folderName = entriesRef.current[index]?.folderName
stagingId, const endGitLog = startTimedLog('Git upload', { folderName, stagingId })
secretRef.current, let gitResult: Awaited<ReturnType<typeof uploadGit>>
(pct) => updateEntry(index, { progress: 50 + Math.round(pct / 2) }),
signal, try {
) gitResult = await uploadGit(
stagingId,
secretRef.current,
(pct) => updateEntry(index, { progress: 50 + Math.round(pct / 2) }),
signal,
)
endGitLog(gitResult.success ? 'done' : 'failed', { error: gitResult.error })
} catch (err) {
endGitLog(signal?.aborted ? 'cancelled' : 'failed', {
error: err instanceof Error ? err.message : 'Erreur inconnue',
})
throw err
}
updateEntry(index, { updateEntry(index, {
status: gitResult.success ? 'success' : 'error', status: gitResult.success ? 'success' : 'error',
@@ -109,12 +145,27 @@ export function useUploadOrchestrator({
driveError: undefined, driveError: undefined,
}) })
const driveResult = await uploadDrive( const endDriveLog = startTimedLog('Drive upload', {
folderName: folderEntry.folderName,
stagingId, stagingId,
secretRef.current, action: driveAction,
driveAction as 'new' | 'replace', })
controller.signal, let driveResult: Awaited<ReturnType<typeof uploadDrive>>
)
try {
driveResult = await uploadDrive(
stagingId,
secretRef.current,
driveAction as 'new' | 'replace',
controller.signal,
)
endDriveLog(driveResult.success ? 'done' : 'failed', { error: driveResult.error })
} catch (err) {
endDriveLog(controller.signal.aborted ? 'cancelled' : 'failed', {
error: err instanceof Error ? err.message : 'Erreur inconnue',
})
throw err
}
if (!driveResult.success) { if (!driveResult.success) {
updateEntry(i, { driveStatus: 'error', driveError: driveResult.error }) updateEntry(i, { driveStatus: 'error', driveError: driveResult.error })
@@ -155,14 +206,45 @@ export function useUploadOrchestrator({
abortRef.current = controller abortRef.current = controller
try { try {
const staged = await stageUpload(folder, secretRef.current, controller.signal) const endStageLog = startTimedLog('Verification: staging upload', {
folderName: folder.folderName,
files: 1 + folder.textures.length,
modelSize: folder.modelFile.size,
})
let staged: Awaited<ReturnType<typeof stageUpload>>
try {
staged = await stageUpload(folder, secretRef.current, controller.signal)
endStageLog('done', { stagingId: staged.stagingId, filesCount: staged.filesCount })
} catch (err) {
endStageLog(controller.signal.aborted ? 'cancelled' : 'failed', {
error: err instanceof Error ? err.message : 'Erreur inconnue',
})
throw err
}
stagingIdRef.current = staged.stagingId stagingIdRef.current = staged.stagingId
const check = await checkFolderDiffs( const endCheckLog = startTimedLog('Verification: GitHub diff check', {
staged.stagingId, folderName: folder.folderName,
secretRef.current, stagingId: staged.stagingId,
controller.signal, })
) let check: CheckResult
try {
check = await checkFolderDiffs(
staged.stagingId,
secretRef.current,
controller.signal,
)
endCheckLog('done', { exists: check.exists, diffs: check.diffs.length })
} catch (err) {
endCheckLog(controller.signal.aborted ? 'cancelled' : 'failed', {
error: err instanceof Error ? err.message : 'Erreur inconnue',
})
throw err
}
checkResultRef.current = check checkResultRef.current = check
if (check.exists) { if (check.exists) {