selecting only tamed mobs

i wanna make pets invincible while theyre standing on diamond blocks. to do this, my idea was to use the @e selector, but that'll cause lag, especially since ill probably have to go into the nbt to check if the mob has an owner. is there a better way?
Continue to help post