Shopware 6 Plugin: How can I check wildcard emails against a blacklist

I have developed a Shopware 6 plugin that checks if an email is in a blacklist before allowing reviews. It works but currently does a database query for every email being checked. If I am in a scheduled task run that sends out 50 emails and I have 1000 entries with wildcard entries, this code won’t work anymore.

I would like to optimize the plugin to:

  • Support wildcard patterns in the blacklist (e.g. *@amazon.com)
  • Fetch the blacklist once and loop through it instead of separate queries

Here is the current code:

use MonologLogger;
use ShopwareCoreFrameworkContext;
use ShopwareCoreFrameworkDataAbstractionLayerEntityRepository;
use SwaProductReviewsComponentsLoggerHelper;
use ShopwareCoreFrameworkDataAbstractionLayerSearchCriteria;
use ShopwareCoreFrameworkDataAbstractionLayerSearchFilterEqualsFilter;


class MailWithBlacklist {
    private EntityRepository $blacklistRepository;
    protected LoggerHelper $loggerHelper;
    
    public function __construct(EntityRepository $blacklistRepository, LoggerHelper $loggerHelper) {
        $this->blacklistRepository = $blacklistRepository;
        $this->loggerHelper = $loggerHelper;
    }
    
    /**
     * 
     * @param string $email
     * @param Context $context
     * @return bool
     */
    public function isEmailBlacklisted(string $email, Context $context): bool
    {

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('email', $email));

        
        $blacklistEntry = $this->blacklistRepository->search($criteria, $context)->first();

        $this->loggerHelper->addDirectRecord(Logger::DEBUG, 'end of isEmailBlacklisted' , ['blacklistEntry' => $blacklistEntry]);
        return $blacklistEntry !== null;
    }
}

How can I modify this code?

Any help is appreciated.