Looking through the code of this add-on, it looks pretty solid, but I've found a few places that could use a bit of improvement. None of it is a real deal-breaker, but for big sites, this would have a positive effect on performance.
In
Repository\UpgradeCoupons, there is a handful of complicated add-on enabled checks that consume a database query each when they should not. For reference:
PHP:
$addon = \XF::em()
->getFinder('XF:AddOn')
->where([
'addon_id' => 'XenSoluce/UserUpgradePro',
'active' => 1
])
->fetchOne();
if(empty($addon))
{
return false;
}
return true;
Should be replaced simply with
PHP:
$cache = \XF::app()->container('addon.cache');
return !empty($cache['XenSoluce/UserUpgradePro']);
In
XF\Purchasable\UserUpgrade, around Line 119, the user upgrade is queried when it was previously already queried in Line 109.
In
Entity\UpgradeCoupons, the pre-save check launches a DB query to determine whether the coupon code is unique. This can be achieved by using the
'unique' => 'xs_uc_promo_code_must_be_unique' value on the entity column without extra code. Ideally, the database column should also be declared unique.