Skip to content

Commit

Permalink
v1.5.45 - Incremental Full Recalc Improvements (#406)
Browse files Browse the repository at this point in the history
* Incremental improvements again being made to full recalcs - this time by ensuring stateful variables are actually being populated correctly when a full recalc is batched
  • Loading branch information
jamessimone authored Jan 27, 2023
1 parent 871262f commit 2de2246
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ As well, don't miss [the Wiki](../../wiki), which includes more advanced informa

## Deployment & Setup

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjXeAAI">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjY8AAI">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjXeAAI">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjY8AAI">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apex-rollup",
"version": "1.5.44",
"version": "1.5.45",
"description": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions rollup-namespaced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ For more info, see the base `README`.

## Deployment & Setup

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjXjAAI">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjYDAAY">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjXjAAI">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008fjYDAAY">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
7 changes: 4 additions & 3 deletions rollup-namespaced/sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"default": true,
"package": "apex-rollup-namespaced",
"path": "rollup-namespaced/source/rollup",
"versionName": "Logging granularity updates",
"versionNumber": "1.0.17.0",
"versionName": "Continuing to chip away on the performance and functionality with full recalcs",
"versionNumber": "1.0.18.0",
"versionDescription": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"releaseNotesUrl": "https://github.com/jamessimone/apex-rollup/releases/latest",
"unpackagedMetadata": {
Expand Down Expand Up @@ -38,6 +38,7 @@
"apex-rollup-namespaced@1.0.14-0": "04t6g000008fjT3AAI",
"apex-rollup-namespaced@1.0.15-0": "04t6g000008fjTmAAI",
"apex-rollup-namespaced@1.0.16-0": "04t6g000008fjWCAAY",
"apex-rollup-namespaced@1.0.17-0": "04t6g000008fjXjAAI"
"apex-rollup-namespaced@1.0.17-0": "04t6g000008fjXjAAI",
"apex-rollup-namespaced@1.0.18-0": "04t6g000008fjYDAAY"
}
}
30 changes: 14 additions & 16 deletions rollup/core/classes/RollupAsyncProcessor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
private final SObjectField lookupFieldOnLookupObject;
private final SObjectField opFieldOnCalcItem;
private final SObjectType lookupObj;
private final SObjectField opFieldOnLookupObject;

private Integer stackDepth = 0;
private List<SObject> lookupItems;
Expand All @@ -17,9 +18,8 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
protected Boolean isProcessed = false;
protected Boolean overridesRunCalc = false;
protected Boolean shouldSortToFront = false;
protected final SObjectField opFieldOnLookupObject;
protected final SObjectType calcItemType;
protected RollupFullRecalcProcessor fullRecalcProcessor;
protected final SObjectType calcItemType;

@TestVisible
private static Boolean shouldRunAsBatch = false;
Expand All @@ -36,10 +36,10 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
REPARENTED
}

protected final Set<String> previouslyResetParents {
private final Set<String> previouslyResetParents {
get {
if (previouslyResetParents == null) {
previouslyResetParents = this.fullRecalcProcessor != null ? this.fullRecalcProcessor.previouslyResetParents : new Set<String>();
previouslyResetParents = new Set<String>();
}
return previouslyResetParents;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
this.stackDepth = innerRollup.stackDepth;
this.calcItemReplacer = innerRollup.calcItemReplacer;
this.lookupItems = innerRollup.lookupItems;
this.previouslyResetParents.addAll(innerRollup.previouslyResetParents);
this.previouslyResetParents.addAll(innerRollup.getPreviouslyResetParents());
this.calcObjectToUniqueFieldNames = innerRollup.calcObjectToUniqueFieldNames;
this.lookupObjectToUniqueFieldNames = innerRollup.lookupObjectToUniqueFieldNames;
}
Expand Down Expand Up @@ -614,7 +614,7 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
}

List<SObject> localLookupItems = this.getLookupItems(calcItemsByLookupField, updatedLookupRecords, roll);
this.logger.log('starting rollup for:', roll, LoggingLevel.INFO);
this.logger.log(this.getTypeName() + ' starting rollup for:', roll, LoggingLevel.INFO);
updatedLookupRecords.putAll(this.getUpdatedLookupItemsByRollup(roll, calcItemsByLookupField, localLookupItems));
}

Expand All @@ -624,7 +624,6 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
this.getDML().doUpdate(updatedLookupRecords.values());
this.populateOtherDeferredRollups();
this.processDeferredRollups();
this.logger.save();
}

protected virtual List<RollupAsyncProcessor> transformFullRecalcRollups() {
Expand Down Expand Up @@ -663,8 +662,12 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
return this.hasParentRollupFieldBeenReset(String.valueOf(processor.opFieldOnLookupObject), parent);
}

protected virtual Set<String> getPreviouslyResetParents() {
return this.previouslyResetParents;
}

protected void addToPreviouslyResetParents(RollupAsyncProcessor processor, SObject parent) {
this.previouslyResetParents.add(this.getParentResetKey(String.valueOf(processor.opFieldOnLookupObject), parent));
this.getPreviouslyResetParents().add(this.getParentResetKey(String.valueOf(processor.opFieldOnLookupObject), parent));
}

protected virtual Boolean getCanRollupWithoutCustomSetting() {
Expand All @@ -673,17 +676,12 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme

private void clearPreviouslyResetParents(RollupAsyncProcessor processor, SObject parent) {
String key = this.getParentResetKey(String.valueOf(processor.opFieldOnLookupObject), parent);
this.previouslyResetParents.remove(key);
this.fullRecalcProcessor?.previouslyResetParents.remove(key);
this.getPreviouslyResetParents().remove(key);
}

private Boolean hasParentRollupFieldBeenReset(String rollupFieldName, SObject parent) {
String resetKey = this.getParentResetKey(rollupFieldName, parent);
Boolean hasParentRollupFieldBeenReset = this.previouslyResetParents.contains(resetKey);
if (this.fullRecalcProcessor != null && hasParentRollupFieldBeenReset == false) {
hasParentRollupFieldBeenReset = this.fullRecalcProcessor.previouslyResetParents.contains(resetKey);
}
return hasParentRollupFieldBeenReset;
return this.getPreviouslyResetParents().contains(resetKey);
}

private Boolean getCanEnqueue() {
Expand Down Expand Up @@ -1146,7 +1144,7 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
}

private void populateReparentedItems(RollupAsyncProcessor roll, List<SObject> localCalcItems, Map<String, List<SObject>> oldLookupItems) {
if (this.isEmptyReparentingSet(roll.op) || roll.oldCalcItems?.isEmpty() == true) {
if (roll.oldCalcItems?.isEmpty() == true || this.isEmptyReparentingSet(roll.op)) {
return;
}
for (Integer index = localCalcItems.size() - 1; index >= 0; index--) {
Expand Down
9 changes: 8 additions & 1 deletion rollup/core/classes/RollupFullBatchRecalculator.cls
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public without sharing virtual class RollupFullBatchRecalculator extends RollupFullRecalcProcessor implements Database.Stateful, Database.RaisesPlatformEvents {
protected final Set<String> statefulPreviouslyResetParents = new Set<String>();

public RollupFullBatchRecalculator(
String queryString,
InvocationPoint invokePoint,
Expand All @@ -17,7 +19,7 @@ public without sharing virtual class RollupFullBatchRecalculator extends RollupF
}

public virtual override void execute(Database.BatchableContext bc, List<SObject> calcItems) {
this.logger.log('starting full batch chunk:', this, LoggingLevel.INFO);
this.logger.log('starting full batch chunk for: ' + this.rollupMetas.size() + ' rollups', LoggingLevel.INFO);
/**
* this batch class is a glorified "for loop" for the calc items, dispatching
* them to the overall Rollup framework while breaking us out of the query limits
Expand All @@ -27,6 +29,7 @@ public without sharing virtual class RollupFullBatchRecalculator extends RollupF
*/
this.process(this.getDelegatedFullRecalcRollups(calcItems));
this.logger.log('batch chunk end', LoggingLevel.INFO);
this.logger.save();
}

public override Boolean isBatch() {
Expand All @@ -47,4 +50,8 @@ public without sharing virtual class RollupFullBatchRecalculator extends RollupF
protected virtual override String startAsyncWork() {
return this.startBatchProcessor();
}

protected override Set<String> getPreviouslyResetParents() {
return this.statefulPreviouslyResetParents;
}
}
1 change: 0 additions & 1 deletion rollup/core/classes/RollupFullRecalcProcessor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public abstract without sharing class RollupFullRecalcProcessor extends RollupAs
this.recordIds = recordIds;
this.postProcessor = postProcessor;
this.overrideRollupControl();
this.previouslyResetParents = new Set<String>();
}

public virtual Boolean isBatch() {
Expand Down
2 changes: 1 addition & 1 deletion rollup/core/classes/RollupLogger.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public without sharing virtual class RollupLogger implements ILogger {
@TestVisible
// this gets updated via the pipeline as the version number gets incremented
private static final String CURRENT_VERSION_NUMBER = 'v1.5.44';
private static final String CURRENT_VERSION_NUMBER = 'v1.5.45';
private static final LoggingLevel FALLBACK_LOGGING_LEVEL = LoggingLevel.DEBUG;
private static final RollupPlugin PLUGIN = new RollupPlugin();

Expand Down
14 changes: 4 additions & 10 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"default": true,
"package": "apex-rollup",
"path": "rollup",
"versionName": "Logging granularity updates",
"versionNumber": "1.5.44.0",
"versionName": "Continuing to chip away on the performance and functionality with full recalcs",
"versionNumber": "1.5.45.0",
"versionDescription": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"releaseNotesUrl": "https://github.com/jamessimone/apex-rollup/releases/latest",
"unpackagedMetadata": {
Expand Down Expand Up @@ -99,17 +99,11 @@
"Apex Rollup - Rollup Callback@0.0.3-0": "04t6g000008Sis0AAC",
"Nebula Logger - Core@4.8.0-NEXT-ignore-origin-method": "04t5Y0000015lslQAA",
"apex-rollup": "0Ho6g000000TNcOCAW",
"apex-rollup@1.5.33-0": "04t6g000007zLvtAAE",
"apex-rollup@1.5.34-0": "04t6g000007zLxGAAU",
"apex-rollup@1.5.35-0": "04t6g000007zM2bAAE",
"apex-rollup@1.5.36-0": "04t6g000007zM78AAE",
"apex-rollup@1.5.37-0": "04t6g000007zMCdAAM",
"apex-rollup@1.5.38-0": "04t6g000008fjOcAAI",
"apex-rollup@1.5.39-0": "04t6g000008fjSFAAY",
"apex-rollup@1.5.40-0": "04t6g000008fjSUAAY",
"apex-rollup@1.5.41-0": "04t6g000008fjSyAAI",
"apex-rollup@1.5.42-0": "04t6g000008fjThAAI",
"apex-rollup@1.5.43-0": "04t6g000008fjW7AAI",
"apex-rollup@1.5.44-0": "04t6g000008fjXeAAI"
"apex-rollup@1.5.44-0": "04t6g000008fjXeAAI",
"apex-rollup@1.5.45-0": "04t6g000008fjY8AAI"
}
}

0 comments on commit 2de2246

Please sign in to comment.