Skip to content

Commit 34a0185

Browse files
committed
fix: Fixed #569
1 parent 94862c8 commit 34a0185

5 files changed

Lines changed: 46 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"repository": "forcedotcom/SFDX-Data-Move-Utility",
8484
"addons": {
8585
"run": {
86-
"version": "1.4.0"
86+
"version": "1.5.0"
8787
}
8888
},
8989
"scripts": {

src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import AddonModule from '../common/addonModule';
3232
import { ISfdmuRunCustomAddonRuntime } from '../../modules/sfdmu-run/custom-addons/package';
3333
import { SfdmuRunCustomAddonService } from './custom';
3434
import ISfdmuRunScript from './ISfdmuRunScript';
35+
import { BulkApiV2_0Engine } from '../../../modules/components/api_engines/bulkApiV2_0Engine';
3536

3637

3738

@@ -206,7 +207,7 @@ export default class SfdmuRunAddonRuntime extends AddonRuntime implements ISfdmu
206207
break;
207208

208209
case API_ENGINE.BULK_API_V2:
209-
apiEngine = new BulkApiV1_0Engine({
210+
apiEngine = new BulkApiV2_0Engine({
210211
logger: this.#logger,
211212
connectionData: this.#script.targetOrg.connectionData,
212213
sObjectName,
@@ -277,7 +278,7 @@ export default class SfdmuRunAddonRuntime extends AddonRuntime implements ISfdmu
277278
async transferContentVersions(module: AddonModule, sourceVersions: ContentVersion[], maxChunkSize?: number): Promise<ContentVersion[]> {
278279

279280
let _self = this;
280-
maxChunkSize = maxChunkSize || CONSTANTS.MAX_CONTENT_VERSION_PROCESSING_MEMORY_SIZE;
281+
maxChunkSize = maxChunkSize || CONSTANTS.DEFAULT_MAX_CHUNK_SIZE;
281282

282283
// All Files of url types to upload ///
283284
let urlUploadJobs = new Array<ContentVersion>();

src/addons/modules/sfdmu-run/ExportFiles/index.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,22 @@ interface IOnExecuteArguments {
4242

4343

4444
/**
45-
*
46-
* For safe uploading binary data, the data is splitted into multiple chunks
47-
* to be uploaded sequentially.
45+
* For optimized porocessing, files are grouped into multiple chunks and uploaded sequentially.
4846
* This parameter defines the maximum size of each chunk (in bytes).
49-
* Default to 15M.
47+
* A size of a single file can exceed this value, but should be up to maxFileSize;
48+
* Default: 15Mb.
49+
* Maximum: 37Mb.
5050
*/
5151
maxChunkSize: number;
52+
53+
/**
54+
* Limits the maximal allowed size of a single file (in bytes) (ContentDocument.ContentSize field)
55+
* Commonly, the SF API is limiting the max size of the API request to 52428800 bytes.
56+
* So, the maximal file size can't be greater then 37Mb. Larger files are ignored and not uploaded.
57+
* Default: 37Mb.
58+
* Maximum: 37Mb
59+
*/
60+
maxFileSize: number;
5261
}
5362

5463
interface IDataToImport {
@@ -87,7 +96,7 @@ export default class ExportFiles extends SfdmuRunAddonModule {
8796
break;
8897

8998
default:
90-
// TODO: Something to do whe is a regular sObject type
99+
// TODO: Something to do when it's a regular sObject type
91100
break;
92101
}
93102

@@ -111,6 +120,17 @@ export default class ExportFiles extends SfdmuRunAddonModule {
111120
return;
112121
}
113122

123+
// Default values
124+
args.maxFileSize = args.maxFileSize || CONSTANTS.DEFAULT_MAX_FILE_SIZE;
125+
if (args.maxFileSize > CONSTANTS.MAX_FILE_SIZE) {
126+
args.maxFileSize = CONSTANTS.MAX_FILE_SIZE;
127+
}
128+
129+
args.maxChunkSize = args.maxChunkSize || CONSTANTS.DEFAULT_MAX_CHUNK_SIZE;
130+
if (args.maxChunkSize > CONSTANTS.MAX_CHUNK_SIZE) {
131+
args.maxChunkSize = CONSTANTS.MAX_CHUNK_SIZE;
132+
}
133+
114134
// Get the relevant parent task
115135
let task = this.runtime.pluginJob.tasks.find(task => task.sObjectName == context.objectName);
116136

@@ -177,9 +197,17 @@ export default class ExportFiles extends SfdmuRunAddonModule {
177197

178198
await this.runtime.transferContentVersions(this, versionsToProcess, args.maxChunkSize);
179199

200+
const failedRecordsCount = versionsToProcess.filter(item => item.isError).length;
201+
180202
this.runtime.logFormattedInfo(this, SFDMU_RUN_ADDON_MESSAGES.ExportFiles_ProcessedRecords,
181203
String(versionsToProcess.length),
182-
String(versionsToProcess.filter(item => item.isError).length));
204+
String(failedRecordsCount));
205+
206+
if (failedRecordsCount == versionsToProcess.length) {
207+
// All content versions are failed => Nothing to process
208+
exportedFilesMap.clear();
209+
versionsToProcess = [];
210+
}
183211
}
184212

185213

@@ -384,7 +412,7 @@ export default class ExportFiles extends SfdmuRunAddonModule {
384412
filteredByDocIdsByField,
385413
'ContentVersion',
386414
sourceFiles.docIds,
387-
'IsLatest = true');
415+
`(IsLatest = true) AND (ContentDocument.ContentSize <= ${args.maxFileSize})`);
388416
if (args.sourceWhere) {
389417
queries = queries.map(query => query.replace('WHERE', 'WHERE (' + args.sourceWhere + ') AND (') + ')')
390418
}

src/modules/components/common_components/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,7 @@ export class Common {
11711171
if (parsedWhere) {
11721172
tempQuery.where.left.openParen = 1;
11731173
tempQuery.where.left.closeParen = 1;
1174-
tempQuery.where.right = <WhereClause>{
1175-
left: parsedWhere.where.left
1176-
};
1174+
tempQuery.where.right = parsedWhere.where;
11771175
tempQuery.where.operator = "AND";
11781176
}
11791177
yield composeQuery(tempQuery);

src/modules/components/common_components/statics.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,12 @@ export const CONSTANTS = {
380380

381381

382382
// ------ AddOns -------------------- //
383-
MAX_CONTENT_VERSION_PROCESSING_MEMORY_SIZE: 15000000,
383+
DEFAULT_MAX_CHUNK_SIZE: 15728640,
384+
MAX_CHUNK_SIZE: 38797312,
385+
386+
DEFAULT_MAX_FILE_SIZE: 38797312,
387+
MAX_FILE_SIZE: 38797312,
388+
384389

385390

386391
// ------- Headers ------------------ //

0 commit comments

Comments
 (0)