Optimise DB lookups by ID
Optimise DB lookups by ID

SQLAlchemy caches objects in the database per-session, but cannot cache
queries. A query just generates a list of object primary keys, which is
then used to fetch the corresponding objects from the cache (if possible)
or database. Therefore a query which filters by primary key is a waste of
time, since it just returns (surprise!) the key we started off with. If we
have the primary key (in this case the id field), just look up the object.

Change-Id: I7123c12372b26c0e1b91b2496921c54d9d992cd8
Signed-off-by: Zane Bitter <1899fff8e7db19a598ee9d835aa1a232f82ea264@redhat.com>

rdo-management/heat,cryptickp/heat,takeshineshiro/heat,varunarya10/heat,rh-s/heat,gonzolino/heat,ntt-sic/heat,JioCloud/heat,rdo-management/heat,noironetworks/heat,jasondunsmore/heat,srznew/heat,NeCTAR-RC/heat,pshchelo/heat,jasondunsmore/heat,srznew/heat,noironetworks/heat,steveb/heat,Triv90/Heat,dragorosson/heat,pratikmallya/heat,pratikmallya/heat,maestro-hybrid-cloud/heat,Triv90/Heat,maestro-hybrid-cloud/heat,dims/heat,Triv90/Heat,redhat-openstack/heat,takeshineshiro/heat,pshchelo/heat,cryptickp/heat,miguelgrinberg/heat,rickerc/heat_audit,gonzolino/heat,rh-s/heat,citrix-openstack-build/heat,rickerc/heat_audit,dragorosson/heat,openstack/heat,redhat-openstack/heat,dims/heat,citrix-openstack-build/heat,cwolferh/heat-scratch,ntt-sic/heat,cwolferh/heat-scratch,steveb/heat,openstack/heat,JioCloud/heat,varunarya10/heat,miguelgrinberg/heat,NeCTAR-RC/heat