Fix performance issues for DB API

Two methods were using iterators for filtering out queries while
SQLAlchemy directly offers possibility to filter natively with strong
performance impact.

Change-Id: I1d03a89f71db06b0b2aeb9ff006fa7115ed7a8ce