Optimized categories and tags query to avoid unnecessary joins