CE-847 take in the list of oldRecords - since updateAction will often already have them!

This commit is contained in:
2024-02-12 14:46:56 -06:00
parent ee1c20b1c6
commit b28000932b
3 changed files with 38 additions and 27 deletions

View File

@ -65,13 +65,13 @@ public class RecordAutomationStatusUpdater
{ {
private static final QLogger LOG = QLogger.getLogger(RecordAutomationStatusUpdater.class); private static final QLogger LOG = QLogger.getLogger(RecordAutomationStatusUpdater.class);
/////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// feature flag - by default, will be false - and before setting records to PENDING_UPDATE_AUTOMATIONS, // // feature flag - by default, will be true - before setting records to PENDING_UPDATE_AUTOMATIONS, //
// we will fetch them, to check their current automationStatus - and if they are currently PENDING // // we will fetch them (if we didn't take them in from the caller, which, UpdateAction does if its //
// or RUNNING inserts or updates, we won't update them. This is added to fix cases where an update that // // backend supports it), to check their current automationStatus - and if they are currently PENDING //
// comes in before insert-automations have run, will cause the pending-insert status to be missed. // // or RUNNING inserts or updates, we won't update them. //
/////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
private static boolean skipPreUpdateFetch = new QMetaDataVariableInterpreter().getBooleanFromPropertyOrEnvironment("qqq.recordAutomationStatusUpdater.skipPreUpdateFetch", "QQQ_RECORD_AUTOMATION_STATUS_UPDATER_SKIP_PRE_UPDATE_FETCH", false); private static boolean allowPreUpdateFetch = new QMetaDataVariableInterpreter().getBooleanFromPropertyOrEnvironment("qqq.recordAutomationStatusUpdater.allowPreUpdateFetch", "QQQ_RECORD_AUTOMATION_STATUS_UPDATER_ALLOW_PRE_UPDATE_FETCH", true);
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
// feature flag - by default, we'll memoize the check for triggers - but we can turn it off. // // feature flag - by default, we'll memoize the check for triggers - but we can turn it off. //
@ -86,7 +86,7 @@ public class RecordAutomationStatusUpdater
** for a list of records from a table, set their automation status - based on ** for a list of records from a table, set their automation status - based on
** how the table is configured. ** how the table is configured.
*******************************************************************************/ *******************************************************************************/
public static boolean setAutomationStatusInRecords(QTableMetaData table, List<QRecord> records, AutomationStatus automationStatus, QBackendTransaction transaction) public static boolean setAutomationStatusInRecords(QTableMetaData table, List<QRecord> records, AutomationStatus automationStatus, QBackendTransaction transaction, List<QRecord> oldRecordList)
{ {
if(table == null || table.getAutomationDetails() == null || CollectionUtils.nullSafeIsEmpty(records)) if(table == null || table.getAutomationDetails() == null || CollectionUtils.nullSafeIsEmpty(records))
{ {
@ -116,24 +116,35 @@ public class RecordAutomationStatusUpdater
} }
} }
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// if table uses field-in-table status tracking (and feature flag allows it) // // if table uses field-in-table status tracking, then check the old records, //
// then look the records up before we set them to pending-updates, to avoid // // before we set them to pending-updates, to avoid losing other pending or //
// losing other pending or running status information. We will allow moving // // running status information. We will allow moving from OK or the 2 //
// from OK or the 2 failed statuses into pending-updates - which seems right. // // failed statuses into pending-updates - which seems right. //
//////////////////////////////////////////////////////////////////////////////// // This is added to fix cases where an update that comes in before insert //
if(automationDetails.getStatusTracking() != null && AutomationStatusTrackingType.FIELD_IN_TABLE.equals(automationDetails.getStatusTracking().getType()) && !skipPreUpdateFetch) // -automations have run, will cause the pending-insert status to be missed. //
///////////////////////////////////////////////////////////////////////////////
if(automationDetails.getStatusTracking() != null && AutomationStatusTrackingType.FIELD_IN_TABLE.equals(automationDetails.getStatusTracking().getType()))
{ {
try try
{ {
List<Serializable> pkeysToLookup = records.stream().map(r -> r.getValue(table.getPrimaryKeyField())).toList(); if(CollectionUtils.nullSafeIsEmpty(oldRecordList))
{
///////////////////////////////////////////////////////////////////////////////////////////////
// if we didn't get the oldRecordList as input (though UpdateAction should usually pass it?) //
// then check feature-flag if we're allowed to do a lookup here & now. If so, then do. //
///////////////////////////////////////////////////////////////////////////////////////////////
if(allowPreUpdateFetch)
{
List<Serializable> pkeysToLookup = records.stream().map(r -> r.getValue(table.getPrimaryKeyField())).toList();
oldRecordList = new QueryAction().execute(new QueryInput(table.getName())
.withFilter(new QQueryFilter(new QFilterCriteria(table.getPrimaryKeyField(), QCriteriaOperator.IN, pkeysToLookup)))
.withTransaction(transaction)
).getRecords();
}
}
List<QRecord> freshRecords = new QueryAction().execute(new QueryInput(table.getName()) for(QRecord freshRecord : CollectionUtils.nonNullList(oldRecordList))
.withFilter(new QQueryFilter(new QFilterCriteria(table.getPrimaryKeyField(), QCriteriaOperator.IN, pkeysToLookup)))
.withTransaction(transaction)
).getRecords();
for(QRecord freshRecord : freshRecords)
{ {
Serializable recordStatus = freshRecord.getValue(automationDetails.getStatusTracking().getFieldName()); Serializable recordStatus = freshRecord.getValue(automationDetails.getStatusTracking().getFieldName());
if(AutomationStatus.PENDING_INSERT_AUTOMATIONS.getId().equals(recordStatus) if(AutomationStatus.PENDING_INSERT_AUTOMATIONS.getId().equals(recordStatus)
@ -302,7 +313,7 @@ public class RecordAutomationStatusUpdater
QTableAutomationDetails automationDetails = table.getAutomationDetails(); QTableAutomationDetails automationDetails = table.getAutomationDetails();
if(automationDetails != null && AutomationStatusTrackingType.FIELD_IN_TABLE.equals(automationDetails.getStatusTracking().getType())) if(automationDetails != null && AutomationStatusTrackingType.FIELD_IN_TABLE.equals(automationDetails.getStatusTracking().getType()))
{ {
boolean didSetStatusField = setAutomationStatusInRecords(table, records, automationStatus, transaction); boolean didSetStatusField = setAutomationStatusInRecords(table, records, automationStatus, transaction, null);
if(didSetStatusField) if(didSetStatusField)
{ {
UpdateInput updateInput = new UpdateInput(); UpdateInput updateInput = new UpdateInput();

View File

@ -444,7 +444,7 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
*******************************************************************************/ *******************************************************************************/
private void setAutomationStatusField(InsertInput insertInput) private void setAutomationStatusField(InsertInput insertInput)
{ {
RecordAutomationStatusUpdater.setAutomationStatusInRecords(insertInput.getTable(), insertInput.getRecords(), AutomationStatus.PENDING_INSERT_AUTOMATIONS, insertInput.getTransaction()); RecordAutomationStatusUpdater.setAutomationStatusInRecords(insertInput.getTable(), insertInput.getRecords(), AutomationStatus.PENDING_INSERT_AUTOMATIONS, insertInput.getTransaction(), null);
} }

View File

@ -113,7 +113,6 @@ public class UpdateAction
public UpdateOutput execute(UpdateInput updateInput) throws QException public UpdateOutput execute(UpdateInput updateInput) throws QException
{ {
ActionHelper.validateSession(updateInput); ActionHelper.validateSession(updateInput);
setAutomationStatusField(updateInput);
QTableMetaData table = updateInput.getTable(); QTableMetaData table = updateInput.getTable();
@ -129,6 +128,7 @@ public class UpdateAction
// for "not-found detection", and for the pre-action to use (if there is one) // // for "not-found detection", and for the pre-action to use (if there is one) //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Optional<List<QRecord>> oldRecordList = fetchOldRecords(updateInput, updateInterface); Optional<List<QRecord>> oldRecordList = fetchOldRecords(updateInput, updateInterface);
setAutomationStatusField(updateInput, oldRecordList);
performValidations(updateInput, oldRecordList, false); performValidations(updateInput, oldRecordList, false);
@ -561,9 +561,9 @@ public class UpdateAction
/******************************************************************************* /*******************************************************************************
** If the table being updated uses an automation-status field, populate it now. ** If the table being updated uses an automation-status field, populate it now.
*******************************************************************************/ *******************************************************************************/
private void setAutomationStatusField(UpdateInput updateInput) private void setAutomationStatusField(UpdateInput updateInput, Optional<List<QRecord>> oldRecordList)
{ {
RecordAutomationStatusUpdater.setAutomationStatusInRecords(updateInput.getTable(), updateInput.getRecords(), AutomationStatus.PENDING_UPDATE_AUTOMATIONS, updateInput.getTransaction()); RecordAutomationStatusUpdater.setAutomationStatusInRecords(updateInput.getTable(), updateInput.getRecords(), AutomationStatus.PENDING_UPDATE_AUTOMATIONS, updateInput.getTransaction(), oldRecordList.orElse(null));
} }
} }