PRESIDECMS-3215: Fix webflow step sync site-tenancy caching bug and add migration for orphaned steps#1726
Conversation
…g-bug-in-webflow-configuration-sync'.
…dd migration for orphaned steps - Fix _getExistingSingletonFlowForStartupCheck() to use site-aware caching Prevents subsequent sites from using first site's cached webflow config data - Add WebflowStepOrphanedRecordsFix migration to fix orphaned step foreign keys Updates steps pointing to wrong site's config and removes duplicates
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| var rawflows = $getPresideObject( "webflow_configuration" ).selectData( filter="instance_ref is null" ); | ||
| for( var f in rawFlows ) { | ||
| request._webflowSingletonsStartupCache[ f.webflow_id ] = f; | ||
| request._webflowSingletonsStartupCache[ currentSiteId ][ f.webflow_id ] = f; |
There was a problem hiding this comment.
Site-aware cache populates with all sites' data
The fix creates a site-specific cache bucket at request._webflowSingletonsStartupCache[ currentSiteId ], but the selectData query has no site filter - it fetches configurations from all sites. When multiple sites have configurations with the same webflow_id, the loop overwrites entries and the wrong site's configuration ends up cached. The query needs a site filter or the loop needs to check f.site == currentSiteId before storing.
There was a problem hiding this comment.
The explicit site check isn't needed because Preside's site tenancy handles filtering automatically.
The webflow_configuration object is site-tenanted (@tenant site). When selectData() is called without bypassTenants, Preside filters by the current site context set by event.setSite() in the interceptor (line 126 of PresideCfFlowInterceptors.cfc).
So the query at line 791 only returns records for the current site, and all records in rawFlows are already for currentSiteId.
The fix is making the cache site-aware by using currentSiteId as a key in the cache structure (lines 788-796). This prevents cross-site data reuse—the original bug—without needing an explicit site filter in the loop.
If tenancy weren't working, we'd see broader issues across the system, not just this method.
| } | ||
|
|
||
| private struct function _getExistingSingletonFlowForStartupCheck( required string webflowId ) { | ||
| var currentSiteId = $getRequestContext().getSiteId(); |
There was a problem hiding this comment.
think we need to consider the case where the application isn't had the sites feature enabled
| } | ||
|
|
||
| private struct function _getExistingSingletonFlowForStartupCheck( required string webflowId ) { | ||
| var sitesEnabled = $isFeatureEnabled( "sites" ); |
There was a problem hiding this comment.
Inconsistent site tenancy check may persist caching bug
High Severity
The function uses $isFeatureEnabled("sites") to determine whether to use site-aware caching, but the calling interceptor in PresideCfFlowInterceptors.cfc uses isSiteTenanted (checking the object's @tenant site attribute) to decide whether to loop through sites. These are different checks. When the webflow_configuration object is site-tenanted but the "sites" feature flag is disabled, the interceptor will loop through sites (setting site context), but this function will use flat caching. Since selectData() without bypassTenants will still filter by site tenancy, the first site's data gets cached and incorrectly returned for subsequent sites - the exact bug this PR aims to fix.
There was a problem hiding this comment.
Fixed by using tenancy check instead of sites feature check.
Prevents subsequent sites from using first site's cached webflow config data
Updates steps pointing to wrong site's config and removes duplicates
Note
Fixes site-tenanted caching for singleton webflow configs and adds a DB migration to repair step FK issues.
_getExistingSingletonFlowForStartupCheck()to cache per-site when site tenancy is enabled; introduces_populateSingletonFlowCache()helper to populate cacheWebflowStepOrphanedRecordsFix.cfc:webflow_configuration_steprows when both orphaned and correct-site steps existwebflow_configurationfor their siteWritten by Cursor Bugbot for commit 61cd141. This will update automatically on new commits. Configure here.