fix: export tx more logs

This commit is contained in:
Vasily Zubarev
2025-05-19 14:38:46 +02:00
parent b7475ca57d
commit d2ef3a088a
4 changed files with 52 additions and 58 deletions

View File

@@ -38,6 +38,9 @@ export async function GET(request: Request) {
// Process transactions in chunks to avoid memory issues
for (let i = 0; i < transactions.length; i += TRANSACTIONS_CHUNK_SIZE) {
const chunk = transactions.slice(i, i + TRANSACTIONS_CHUNK_SIZE)
console.log(
`Processing transactions ${i + 1}-${Math.min(i + TRANSACTIONS_CHUNK_SIZE, transactions.length)} of ${transactions.length}`
)
for (const transaction of chunk) {
const row: Record<string, unknown> = {}
@@ -90,8 +93,22 @@ export async function GET(request: Request) {
throw new Error("Failed to create zip folder")
}
let totalFilesProcessed = 0
let totalFilesToProcess = 0
// First count total files to process
for (const transaction of transactions) {
const transactionFiles = await getFilesByTransactionId(transaction.id, user.id)
totalFilesToProcess += transactionFiles.length
}
console.log(`Starting to process ${totalFilesToProcess} files in total`)
for (let i = 0; i < transactions.length; i += FILES_CHUNK_SIZE) {
const chunk = transactions.slice(i, i + FILES_CHUNK_SIZE)
console.log(
`Processing files for transactions ${i + 1}-${Math.min(i + FILES_CHUNK_SIZE, transactions.length)} of ${transactions.length}`
)
for (const transaction of chunk) {
const transactionFiles = await getFilesByTransactionId(transaction.id, user.id)
@@ -108,6 +125,9 @@ export async function GET(request: Request) {
for (const file of transactionFiles) {
const fullFilePath = fullPathForFile(user, file)
if (await fileExists(fullFilePath)) {
console.log(
`Processing file ${++totalFilesProcessed}/${totalFilesToProcess}: ${file.filename} for transaction ${transaction.id}`
)
const fileData = await fs.readFile(fullFilePath)
const fileExtension = path.extname(fullFilePath)
transactionFolder.file(
@@ -116,11 +136,15 @@ export async function GET(request: Request) {
}${fileExtension}`,
fileData
)
} else {
console.log(`Skipping missing file: ${file.filename} for transaction ${transaction.id}`)
}
}
}
}
console.log(`Finished processing all ${totalFilesProcessed} files`)
// Generate zip with progress tracking
const zipContent = await zip.generateAsync({
type: "uint8array",