-
-
Notifications
You must be signed in to change notification settings - Fork 485
[4.x] Improve resource syncing (refactor + mapping cleanup + morph maps) #1411
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1411 +/- ##
============================================
+ Coverage 85.79% 85.89% +0.10%
- Complexity 1137 1143 +6
============================================
Files 181 184 +3
Lines 3329 3353 +24
============================================
+ Hits 2856 2880 +24
Misses 473 473 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cf01ce9 to
14d40b3
Compare
Member
|
We should also support using a |
cbd2f45 to
3974ad0
Compare
stancl
reviewed
Nov 21, 2025
b1c533c to
f53fcb2
Compare
66fdf96 to
12df6f1
Compare
Also move pivot record deletion to that listener and improve tests The 'tenant pivot records are deleted along with the tenants to which they belong to' test is failing in this commit -- the listener for deleting mappings when a *tenant* is deleted is only implemented in the next commit. The only change done here is to re-add FKs (necessary for passing *in this commit* in that specific dataset variant) that were removed from the default test migration as we now have the DeleteResourceMapping listener that's enabled by default.
Also make all resource syncing-related listener closures static. Also correct return type for getGlobalIdentifierKey to string|int. (We intentionally do not support returning null like many other "get x key" methods would since such a case might break resource syncing logic. This is also why we use inline getAttribute() in the creating listener instead of calling the method.)
The old names of the class and method were misleading. We don't actually need any relation. And we don't even need a model instance as we were returning previously -- the only use of that method was in TriggerSyncingEvents which would immediately use ::class on the returned value. Therefore, all we are asking for in this interface is just the central resource class.
12df6f1 to
04a20ca
Compare
e85ee25 to
159e600
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds listeners for handling cleanup of pivot records/mappings
SyncedResourceDeleted(fired when any synced resource is deleted),DeleteResourceMapping. Previously, the cleanup was only happening onSyncMaster/central resource deletion. Now,triggerDeleteEventis called while deleting/force deleting any synced resource, making the cleanup possible even for tenant resources.TenantDeleted,DeleteAllTenantMappings-- commented out by default (until now, the pivot records were only getting deleted when the tenant key column had a constraint, and the constraint hadonDelete('cascade')-- db-level)This PR also improves some resource syncing implementation details, for example, the
ResourceSyncingtrait now usesstatic::deleted()instead ofstatic::deleting(), which is safer. TheSyncedResourceDeletedevent with theDeleteResourceMappinglistener also lets us separate the resource x pivot record deletion concerns, and improve the performance (e.g. the mass delete of pivot records whenSyncMaster's deleted instead of a for loop where we were deleting the pivot records one by one).The
PivotWithRelationinterface got simplified and renamed toPivotWithCentralResource. The interface now only requires thegetCentralResourceClass(): stringmethod that should return the central resource's class name (instead of a model instance).We also move global ID generation to a separate method to make it easily overridable, in case a developer wants to use different UniqueIdentifierGenerator than the one used for tenant IDs.
We also add support for morph maps.