Browse Source

fix: PR requested changes

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

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

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

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

@ -46,6 +46,11 @@ export class InitMigrationJobs {
// check for lock // check for lock
if (migrationJobsState.locked) { 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 // migration job is running, make sure it's not stalled by checking after 10 mins
// stall check is updated every 5 mins // stall check is updated every 5 mins
setTimeout(() => { setTimeout(() => {
@ -71,7 +76,7 @@ export class InitMigrationJobs {
await updateMigrationJobsState(migrationJobsState, migrationJobsState); await updateMigrationJobsState(migrationJobsState, migrationJobsState);
// wait for 2 seconds to confirm lock // 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(); const confirmState = await getMigrationJobsState();

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

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

Loading…
Cancel
Save