Performance: Improve performance when adding a summary calculation

Rebuild and update of the project tree for summary objects in Data Sources can be time consuming for large cases. Make sure the update of UI only happens when required.
This commit is contained in:
Magne Sjaastad 2024-05-08 07:06:12 +02:00
parent aae5f55dc2
commit 0ba11af5a4
4 changed files with 37 additions and 7 deletions

View File

@ -349,7 +349,7 @@ void RimSummaryAddressCollection::deleteChildren()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryAddressCollection::deleteCalculatedObjects()
int RimSummaryAddressCollection::deleteCalculatedAddresses()
{
std::vector<RimSummaryAddress*> toDelete;
for ( const auto& a : m_adresses )
@ -360,6 +360,8 @@ void RimSummaryAddressCollection::deleteCalculatedObjects()
}
}
int calculationAddressCount = static_cast<int>( toDelete.size() );
for ( auto a : toDelete )
{
m_adresses.removeChild( a );
@ -368,8 +370,10 @@ void RimSummaryAddressCollection::deleteCalculatedObjects()
for ( auto& folder : m_subfolders )
{
folder->deleteCalculatedObjects();
calculationAddressCount += folder->deleteCalculatedAddresses();
}
return calculationAddressCount;
}
//--------------------------------------------------------------------------------------------------

View File

@ -66,7 +66,7 @@ public:
void updateFolderStructure( const std::set<RifEclipseSummaryAddress>& addresses, int caseId, int ensembleId = -1 );
void deleteChildren();
void deleteCalculatedObjects();
int deleteCalculatedAddresses();
bool isEmpty() const;
bool isEnsemble() const;

View File

@ -397,14 +397,40 @@ void RimSummaryCase::onCalculationUpdated()
// NB! Performance critical method
if ( !m_showSubNodesInTree ) return;
if ( m_dataVectorFolders->isEmpty() )
{
// Build the child nodes if they are not already built. This function will also create the
// calculated objects so we can do a early return.
refreshMetaData();
return;
}
// Delete all calculated address objects
m_dataVectorFolders->deleteCalculatedObjects();
auto deletedCalculatedObjectCount = m_dataVectorFolders->deleteCalculatedAddresses();
int calculatedAddressCount = 0;
if ( auto reader = summaryReader() )
{
auto addresses = reader->allResultAddresses();
m_dataVectorFolders->updateFolderStructure( addresses, m_caseId );
std::set<RifEclipseSummaryAddress> calculatedAddresses;
for ( const auto& adr : addresses )
{
if ( adr.isCalculated() )
{
calculatedAddresses.insert( adr );
}
}
calculatedAddressCount = static_cast<int>( calculatedAddresses.size() );
m_dataVectorFolders->updateFolderStructure( calculatedAddresses, m_caseId );
}
updateConnectedEditors();
if ( deletedCalculatedObjectCount > 0 || calculatedAddressCount > 0 )
{
updateConnectedEditors();
}
}

View File

@ -1162,7 +1162,7 @@ void RimSummaryCaseCollection::buildMetaData()
//--------------------------------------------------------------------------------------------------
void RimSummaryCaseCollection::onCalculationUpdated()
{
m_dataVectorFolders->deleteCalculatedObjects();
m_dataVectorFolders->deleteCalculatedAddresses();
m_dataVectorFolders->updateFolderStructure( ensembleSummaryAddresses(), -1, m_ensembleId );
m_analyzer.reset();