avoid unnecessary db queries

Change-Id: Ia4c37c45025e85f978b0c6778e7c7f29b78a4258
Reviewed-on: http://review.couchbase.org/31139
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>