hotfix: updated to null out the getoutput's record if it was not returned by the original source

This commit is contained in:
Tim Chamberlain
2023-05-16 12:02:47 -05:00
parent 01d3937889
commit 3f9370e9b5

View File

@ -235,13 +235,23 @@ public class GetAction
Instant cachedDate = cachedRecord.getValueInstant(table.getCacheOf().getCachedDateFieldName()); Instant cachedDate = cachedRecord.getValueInstant(table.getCacheOf().getCachedDateFieldName());
if(cachedDate == null || cachedDate.isBefore(Instant.now().minus(expirationSeconds, ChronoUnit.SECONDS))) if(cachedDate == null || cachedDate.isBefore(Instant.now().minus(expirationSeconds, ChronoUnit.SECONDS)))
{ {
QRecord recordFromSource = tryToGetFromCacheSource(getInput); //////////////////////////////////////////////////////////////////////////
boolean shouldDeleteCachedRecord = true; // keep the serial key from the old record in case we need to delete it //
//////////////////////////////////////////////////////////////////////////
Serializable oldRecordPrimaryKey = getOutput.getRecord().getValue(table.getPrimaryKeyField());
boolean shouldDeleteCachedRecord = true;
///////////////////////////////////////////
// fetch record from original source now //
///////////////////////////////////////////
QRecord recordFromSource = tryToGetFromCacheSource(getInput);
if(recordFromSource != null) if(recordFromSource != null)
{ {
/////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// if the record was found in the source, update it in the cache // // if the record was found in the source, put it into the output //
/////////////////////////////////////////////////////////////////// // object so returned back to caller, check that it should actually //
// be cached before doing so //
//////////////////////////////////////////////////////////////////////
QRecord recordToCache = mapSourceRecordToCacheRecord(table, recordFromSource); QRecord recordToCache = mapSourceRecordToCacheRecord(table, recordFromSource);
recordToCache.setValue(table.getPrimaryKeyField(), cachedRecord.getValue(table.getPrimaryKeyField())); recordToCache.setValue(table.getPrimaryKeyField(), cachedRecord.getValue(table.getPrimaryKeyField()));
getOutput.setRecord(recordToCache); getOutput.setRecord(recordToCache);
@ -256,6 +266,13 @@ public class GetAction
shouldDeleteCachedRecord = false; shouldDeleteCachedRecord = false;
} }
} }
else
{
///////////////////////////////////////////////////////////////////////////////////////
// if we did not get a record back from the source, empty out the getOutput's record //
///////////////////////////////////////////////////////////////////////////////////////
getOutput.setRecord(null);
}
if(shouldDeleteCachedRecord) if(shouldDeleteCachedRecord)
{ {
@ -264,7 +281,7 @@ public class GetAction
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
DeleteInput deleteInput = new DeleteInput(); DeleteInput deleteInput = new DeleteInput();
deleteInput.setTableName(getInput.getTableName()); deleteInput.setTableName(getInput.getTableName());
deleteInput.setPrimaryKeys(List.of(getOutput.getRecord().getValue(table.getPrimaryKeyField()))); deleteInput.setPrimaryKeys(List.of(oldRecordPrimaryKey));
new DeleteAction().execute(deleteInput); new DeleteAction().execute(deleteInput);
} }
} }