Draft: Find the other default domains by query, without loading them
Follow-up of https://www.drupal.org/project/domain/issues/3642166 for 4.x: the same change as in the 3.x and 3.0.x backports (!510 (merged), !511 (merged)).
Domain::preSave() and postSave() looked for the other default domains by loading every default domain, on every domain save. They now find them with an ID query (Domain::getOtherDefaultIds()), and load a domain only when it must stop being the default.
Loading domains runs the domain load hooks, like the one of domain_alias, which reads the active domain: on 3.0.x, loading them while saving a domain negotiated the active domain too early. On 4.x it is work every domain save did for nothing: re-saving a domain that is not the default loaded the default domain twice.
Tests
DomainSaveLoadsTest records the domains loaded during saves (through domain_test's hook_domain_load()): re-saving a domain that is not the default loads no other domain, and making it the default loads the previous default only. It fails without the change. The loads of the saved domain itself (core's unchanged copy and the hostname uniqueness check) are unchanged.
AI-Generated: Yes (Claude Code wrote the change, its test and this description. I reviewed them.)