Fixed cache state dependence for assertNumQueries in test_group_permission_performance.

Refs #20432 and #23746.
Fixed #23641 -- Moved post_migrate signals for contrib apps to AppConfig.ready().