Skip to content

Commit

Permalink
Move pattern_matching_rois to default query
Browse files Browse the repository at this point in the history
  • Loading branch information
Tooseriuz committed Aug 7, 2024
1 parent 94d8ae7 commit f82717d
Showing 1 changed file with 33 additions and 67 deletions.
100 changes: 33 additions & 67 deletions apps/cli/src/backup/projects/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,77 +126,43 @@ export const generateCsvs = async (
return allCSVFiles
}

if (item === 'pattern_matching_rois' && !minimum) {
const allRecords = fetchAllRecordsUsingSubquery<{ project_id: number }>(
'pattern_matchings',
item,
{ projectId },
(t) => ({ projectId: t.project_id }),
sequelize,
storage,
legacyStorage,
verbose
)
let totalRows = 1 // headers as first row
let rowCount = 1 // headers as first row
let fileCount = 1
let fileName = `${item}.${String(fileCount).padStart(4, '0')}.csv`
const allCSVFiles = [fileName]
for await (const records of allRecords) {
if (!allCSVFiles.includes(fileName)) {
allCSVFiles.push(fileName)
}
await convertToCsv(fileName, records)
rowCount += records.length - 1
if (rowCount >= BATCH_SIZE) {
fileCount++
totalRows += rowCount
rowCount = 1
fileName = `${item}.${String(fileCount).padStart(4, '0')}.csv`
}
}

if (verbose === true) {
console.info(`Fetched ${totalRows} records in ${fileCount} file(s) for ${item}`)
}
return allCSVFiles
}

if (!['recordings', 'playlist_recordings', 'pattern_matching_rois'].includes(item)) {
const recordsGenerator = fetchAllRecords(
item,
query,
sequelize,
{ projectId },
storage,
legacyStorage,
signedUrls,
verbose
)
if (!['recordings', 'playlist_recordings'].includes(item)) {
if (item !== 'pattern_matching_rois' || !minimum) {
const recordsGenerator = fetchAllRecords(
item,
query,
sequelize,
{ projectId },
storage,
legacyStorage,
signedUrls,
verbose
)

let totalRows = 1 // headers as first row
let rowCount = 1 // headers as first row
let fileCount = 1
let fileName = `${item}.${String(fileCount).padStart(4, '0')}.csv`
const allCSVFiles = [fileName]
for await (const records of recordsGenerator) {
if (!allCSVFiles.includes(fileName)) {
allCSVFiles.push(fileName)
}
await convertToCsv(fileName, records)
rowCount += records.length - 1
if (rowCount >= BATCH_SIZE) {
fileCount++
totalRows += rowCount
rowCount = 1
fileName = `${item}.${String(fileCount).padStart(4, '0')}.csv`
let totalRows = 1 // headers as first row
let rowCount = 1 // headers as first row
let fileCount = 1
let fileName = `${item}.${String(fileCount).padStart(4, '0')}.csv`
const allCSVFiles = [fileName]
for await (const records of recordsGenerator) {
if (!allCSVFiles.includes(fileName)) {
allCSVFiles.push(fileName)
}
await convertToCsv(fileName, records)
rowCount += records.length - 1
if (rowCount >= BATCH_SIZE) {
fileCount++
totalRows += rowCount
rowCount = 1
fileName = `${item}.${String(fileCount).padStart(4, '0')}.csv`
}
}
}

if (verbose === true) {
console.info(`Fetched ${totalRows} records in ${fileCount} file(s) for ${item}`)
if (verbose === true) {
console.info(`Fetched ${totalRows} records in ${fileCount} file(s) for ${item}`)
}
return allCSVFiles
}
return allCSVFiles
}
return []
}
Expand Down

0 comments on commit f82717d

Please sign in to comment.