Browse Source

fix: better scan and confirm existing ids

nc-feat/attachment-clean-up
mertmit 4 months ago
parent
commit
ad4b5f671c
  1. 1
      packages/nocodb/src/models/FileReference.ts
  2. 27
      packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

1
packages/nocodb/src/models/FileReference.ts

@ -29,6 +29,7 @@ export default class FileReference {
ncMeta = Noco.ncMeta,
) {
const insertObj = extractProps(fileRefObj, [
'id',
'storage',
'file_url',
'file_size',

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

@ -86,8 +86,13 @@ export class AttachmentMigration {
fileReferenceBuffer.push({ file_path: file });
if (fileReferenceBuffer.length >= 100) {
fileScanStream.pause();
try {
const processBuffer = fileReferenceBuffer.splice(0);
const processBuffer = fileReferenceBuffer.splice(
0,
fileReferenceBuffer.length,
);
filesCount += processBuffer.length;
@ -124,6 +129,8 @@ export class AttachmentMigration {
this.log(e);
err = e;
}
fileScanStream.resume();
}
});
@ -370,6 +377,24 @@ export class AttachmentMigration {
});
updateRequired = true;
} else {
const fileReference = await FileReference.get(
context,
attachment.id,
);
if (!fileReference) {
await FileReference.insert(context, {
id: attachment.id,
source_id: source.id,
fk_model_id,
fk_column_id: column.id,
file_url: attachment.path || attachment.url,
file_size: attachment.size,
is_external: !source.isMeta(),
deleted: false,
});
}
}
}
} catch (e) {

Loading…
Cancel
Save