To avoid cycles, use the CYCLE support added in PostgreSQL 14. Unfortunately, this change breaks a number of specs that use mocking, for both PrivateSubnet and Prog::Vnet::SubnetNexus. Change those specs to avoid mocking the related methods. Avoid N+1 queries for SubnetNexus#active_nics and #nics_to_rekey to check the label for the related strands. Instead, join to the strand table and do the filtering in the database. This also allows nics_to_rekey to use a single query for the two labels (wait and wait_setup), instead of a separate query per label. Avoid N+1 query for SubnetNexus#rekeying_nics by eager loading the strands, and do the rekey_payload filter in the database instead of in Ruby. Add SubnetNexus#nics_with_strand_label and #all_connected_nics to DRY up the related code. Remove SubnetNexus#to_be_added_nics, which was only called internally by #nics_to_rekey, and no longer needed there, as it does a single query instead of 2 queries.
7.4 KiB
7.4 KiB