soql – Can anyone write this code in optimized way?

I know it’s not the correct way to write the code like this. But can anyone help me to optimize this code without for loop?

    String userName="test@test.com%";
    List<String> objectNames = new List<String> {'Product_Label__c', 'Line_Item__c', 'Country__c', 'Regieon__c', 'Product_Group__c'};
    Integer count = 0;

    for (String objectName : objectNames){
    count = Database.countQuery('SELECT Count() FROM ' objectName + ' WHERE LastModifiedDate > YESTERDAY AND LastModifiedBy.username LIKE :userName');
        System.debug(objectName+'---->'+count);
        if (count > 0) {
            break;
        }

    }
    if(count==0){
        //do something
    }

Read more here: Source link