Optimize some queries that are always executed when loading base.php

Also created #7331 and owncloud/contacts#422 for other queries found in (almost) every page load

@icewind1991 @PVince81 @DeepDiver1975