Browse Source

fix: PR requested changes

nc-feat/attachment-clean-up
mertmit 4 months ago
parent
commit
c52acce032
  1. 23
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 7
      packages/nocodb/src/modules/jobs/migration-jobs/init-migration-jobs.ts
  3. 24
      packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

23
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5293,9 +5293,7 @@ class BaseModelSqlv2 {
await this.model.getColumns(this.context);
await Promise.all(
insertDatas.map(
async (d) => await this.prepareNocoData(d, true, cookie),
),
insertDatas.map((d) => this.prepareNocoData(d, true, cookie)),
);
}
@ -6006,10 +6004,21 @@ class BaseModelSqlv2 {
for (const c of attachmentColumns) {
if (row[c.column_name]) {
try {
const attachments = JSON.parse(row[c.column_name]);
for (const attachment of attachments) {
if (attachment.id) {
fileReferenceIds.push(attachment.id);
let attachments;
if (typeof row[c.column_name] === 'string') {
attachments = JSON.parse(row[c.column_name]);
for (const attachment of attachments) {
if (attachment.id) {
fileReferenceIds.push(attachment.id);
}
}
}
if (Array.isArray(attachments)) {
for (const attachment of attachments) {
if (attachment.id) {
fileReferenceIds.push(attachment.id);
}
}
}
} catch (e) {

7
packages/nocodb/src/modules/jobs/migration-jobs/init-migration-jobs.ts

@ -46,6 +46,11 @@ export class InitMigrationJobs {
// check for lock
if (migrationJobsState.locked) {
if (migrationJobsState.instance === instanceUuid) {
// lock taken by this instance
return;
}
// migration job is running, make sure it's not stalled by checking after 10 mins
// stall check is updated every 5 mins
setTimeout(() => {
@ -71,7 +76,7 @@ export class InitMigrationJobs {
await updateMigrationJobsState(migrationJobsState, migrationJobsState);
// wait for 2 seconds to confirm lock
await new Promise((resolve) => setTimeout(resolve, 2000));
await new Promise((resolve) => setTimeout(resolve, 5000));
const confirmState = await getMigrationJobsState();

24
packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

@ -140,19 +140,19 @@ export class AttachmentMigrationProcessor {
}
});
await new Promise((resolve, reject) => {
fileScanStream.on('end', resolve);
fileScanStream.on('error', reject);
})
.then(() => {
filesCount += fileReferenceBuffer.length;
this.log(`Completed scanning with ${filesCount} files`);
})
.catch((e) => {
this.log(`There was an error while scanning files`);
this.log(e);
err = e;
try {
await new Promise((resolve, reject) => {
fileScanStream.on('end', resolve);
fileScanStream.on('error', reject);
});
} catch (e) {
this.log(`There was an error while scanning files`);
this.log(e);
throw e;
}
filesCount += fileReferenceBuffer.length;
this.log(`Completed scanning with ${filesCount} files`);
if (err) {
throw err;

Loading…
Cancel
Save