Skip to content

Commit 7d3aa43

Browse files
committed
Implementation of the Maroun-style query more retriever #448
1 parent 4ef668d commit 7d3aa43

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

force-app/main/default/lwc/orgcheckApp/api/core/orgcheck-api-datafactory.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ export class OrgCheckDataFactory2 {
9898
export class OrgCheckDataFactory {
9999

100100
#allValidations;
101-
#needDepencencies;
101+
#needDependencies;
102102
#instances;
103103

104104
constructor(sfdcManager) {
105105

106106
const currentApiVersion = sfdcManager.getApiVersion();
107107

108-
this.#allValidations = [
108+
this.#allValidations = [ // START:ALL_VALIDATIONS
109109
{
110110
description: 'Not referenced anywhere',
111111
formula: (d) => IS_EMPTY(d.dependencies?.referenced),
@@ -359,7 +359,8 @@ export class OrgCheckDataFactory {
359359
badField: 'usedPercentage',
360360
applicable: [ SFDC_Limit ]
361361
}
362-
].map((v, i) => {
362+
] // END:ALL_VALIDATIONS
363+
.map((v, i) => {
363364
// check description
364365
if (v.description === undefined || typeof v.description !== 'string') {
365366
throw new TypeError(`The ${i}th Validation Rule should have a 'description' property of type 'string'.`);
@@ -383,16 +384,16 @@ export class OrgCheckDataFactory {
383384
});
384385
Object.freeze(this.#allValidations);
385386

386-
this.#needDepencencies = [
387+
this.#needDependencies = [ // START:ALL_NEED_DEPENDENCIES
387388
SFDC_ApexClass, SFDC_ApexTrigger, SFDC_Field, SFDC_CustomLabel, SFDC_Flow,
388389
SFDC_LightningAuraComponent, SFDC_LightningPage, SFDC_LightningWebComponent,
389390
SFDC_VisualForceComponent, SFDC_VisualForcePage
390-
];
391+
]; // END:ALL_NEED_DEPENDENCIES
391392
// check if '#needDepencencies' array contains only OrgCheckData instances
392-
if (this.#needDepencencies === undefined || Array.isArray(this.#needDepencencies) === false || this.#needDepencencies.every((dc) => IS_CLASS_EXTENDS(dc, OrgCheckData) === false)) {
393+
if (this.#needDependencies === undefined || Array.isArray(this.#needDependencies) === false || this.#needDependencies.every((dc) => IS_CLASS_EXTENDS(dc, OrgCheckData) === false)) {
393394
throw new TypeError(`The list of classes that needs Dependencies must be of type 'array' with only OrgCheckData items.`);
394395
}
395-
Object.freeze(this.#needDepencencies);
396+
Object.freeze(this.#needDependencies);
396397

397398
this.#instances = new Map();
398399
}
@@ -413,7 +414,7 @@ export class OrgCheckDataFactory {
413414
this.#instances.set(dataClass, new OrgCheckDataFactory2(
414415
dataClass,
415416
isDataClassExtendsData ? this.#allValidations.filter(v => v.applicable.includes(dataClass)) : [],
416-
isDataClassExtendsData ? this.#needDepencencies.includes(dataClass) : []
417+
isDataClassExtendsData ? this.#needDependencies.includes(dataClass) : []
417418
));
418419
}
419420
// Return the instance

force-app/main/default/lwc/orgcheckApp/api/core/orgcheck-api-sfconnectionmanager.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,11 @@ export class OrgCheckSalesforceManager {
276276
let nbQueriesDone = 0, nbQueriesByPassed = 0, nbQueriesError = 0, nbQueryMore = 0, nbQueriesPending = queries.length;
277277
return Promise.all(queries.map((query) => {
278278
const conn = query.tooling === true ? this.#connection.tooling : this.#connection;
279+
let queryMoreStartingId = '000000000000000000';
280+
const uniqueFieldName = query.uniqueFieldName || 'Id';
279281
const sequential_query = (callback) => {
280282
if (query.queryMore === false) {
281-
conn.query(`${query.string} LIMIT ${MAX_NOQUERYMORE_BATCH_SIZE} OFFSET ${nbQueryMore * MAX_NOQUERYMORE_BATCH_SIZE}`, { autoFetch: false }, callback);
283+
conn.query(`${query.string} AND ${uniqueFieldName} > '${queryMoreStartingId}' ORDER BY ${uniqueFieldName} LIMIT ${MAX_NOQUERYMORE_BATCH_SIZE}`, { autoFetch: false }, callback);
282284
} else {
283285
conn.query(query.string, { autoFetch: true }, callback);
284286
}
@@ -306,6 +308,7 @@ export class OrgCheckSalesforceManager {
306308
nbQueriesPending--;
307309
resolve({ records: records });
308310
} else {
311+
queryMoreStartingId = records[records.length-1][uniqueFieldName];
309312
nbQueryMore++;
310313
sequential_query(recursive_query);
311314
}

force-app/main/default/lwc/orgcheckApp/api/dataset/orgcheck-api-dataset-apexclasses.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class OrgCheckDatasetApexClasses extends OrgCheckDataset {
2121
'FROM ApexClass '+
2222
'WHERE ManageableState IN (\'installedEditable\', \'unmanaged\') ',
2323
tooling: true,
24-
queryMore: false
24+
queryMore: false,
25+
uniqueFieldName: 'Id', // unique field name (to be used by the custom QueryMore)
2526
}, {
2627
string: 'SELECT ApexClassOrTriggerId, ApexTestClassId '+
2728
'FROM ApexCodeCoverage',

force-app/main/default/lwc/orgcheckApp/api/dataset/orgcheck-api-dataset-objects.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export class OrgCheckDatasetObjects extends OrgCheckDataset {
1818

1919
// Some information are not in the global describe, we need to append them with EntityDefinition soql query
2020
sfdcManager.soqlQuery([{
21-
queryMore: false, // entityDef does not support calling QueryMore, we will get records with LIMIT/OFFSET
21+
queryMore: false, // entityDef does not support calling QueryMore
22+
uniqueFieldName: 'DurableId', // unique field name (to be used by the custom QueryMore)
2223
string: 'SELECT DurableId, NamespacePrefix, DeveloperName, QualifiedApiName, '+
2324
'ExternalSharingModel, InternalSharingModel '+
2425
'FROM EntityDefinition '+

0 commit comments

Comments
 (0)