Avoid redundant polling of DB for metadata
Avoid redundant polling of DB for metadata

Every time self.metadata is read, it triggers a refresh from the database.
We were accessing it multiple times in a loop, which is not only wasteful
but can get very O(n^2) for a WaitCondition with a high Count.

Partial-Bug: #1306743

Change-Id: I1a82afac6c4ef56dbf87722648034c05abef4010

jasondunsmore/heat,takeshineshiro/heat,dragorosson/heat,srznew/heat,rdo-management/heat,cryptickp/heat,dragorosson/heat,openstack/heat,pratikmallya/heat,srznew/heat,maestro-hybrid-cloud/heat,pshchelo/heat,pratikmallya/heat,noironetworks/heat,rh-s/heat,miguelgrinberg/heat,steveb/heat,gonzolino/heat,jasondunsmore/heat,takeshineshiro/heat,rh-s/heat,cwolferh/heat-scratch,cryptickp/heat,dims/heat,rdo-management/heat,redhat-openstack/heat,openstack/heat,pshchelo/heat,cwolferh/heat-scratch,dims/heat,noironetworks/heat,maestro-hybrid-cloud/heat,gonzolino/heat,steveb/heat,redhat-openstack/heat,miguelgrinberg/heat