Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low performance of CMDT SOQL queries when including FieldDefinition fields #650

Open
mmablom opened this issue Jan 23, 2025 · 1 comment

Comments

@mmablom
Copy link

mmablom commented Jan 23, 2025

While running integration tests for functionality that includes Rollups, I noticed that the SOQL query to retrieve Rollups was taking on average 1 second to complete. This is caused by the inclusion of Relationship fields of the type FieldDefinition in the query, which seems to require a dynamic Schema lookup similar to Describe calls. Comparing query times with or without these fields can be a 20x difference, as seen here:

CUMULATIVE_PROFILING | SOQL operations

AnonymousBlock: line 1, column 1: [
  SELECT Id, LookupFieldOnLookupObjectText__c
  FROM Rollup__mdt
  WHERE DeveloperName = 'WOLI_Part_Request_Expected_Date'
]: executed 1 time in 48 ms

AnonymousBlock: line 7, column 1: [
  SELECT Id, LookupFieldOnLookupObject__c
  FROM Rollup__mdt
  WHERE DeveloperName = 'WOLI_Part_Request_Expected_Date'
]: executed 1 time in 991 ms

I can think of two ways to optimize this in RollupRepository:

  1. As discussed in SFXD; Add an option in Rollup Settings or Rollup Control to toggle querying of the FieldDefinition fields of. This would require all Rollups to use the {field}Text__c fields instead of the Relationship fields. In the RollupRepository the query can then strip out those fields.
  2. Store Rollups including the FieldDefinition fields in the Org Cache and optionally refresh the cache based on the max LastModifiedDate of Rollups. This would (in theory) be be functionally the same for the end user and keep the nice features of FieldDefinitions, such as keeping the reference when a field is renamed. However, I'm not sure if the Org Cache is always available or if there are any other issues that might crop up.

I'd be interested in creating a PR to implement some optimization, let me know what has your preference or if there's any better solution.

@jamessimone
Copy link
Owner

@mmablom thanks for submitting, and yes, very interested in optimizing this. I've created https://github.com/jamessimone/apex-rollup/tree/v1.7.5 in the event that you're interested in creating a PR in the coming days for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants