Commit 8b3469ed authored by Patrick Barroca's avatar Patrick Barroca

dev #46014 : fix newsletters index recipients count performance, limited to index list

parent 22f68425
......@@ -138,7 +138,7 @@ class Class_Newsletter extends Storm_Model_Abstract {
public function getRecipientsUsersIds() {
$ids = [];
foreach($this->getRecipientsGroups() as $group)
foreach($group->getUsersIds() as $id)
foreach($group->getUsersIdsOptimized() as $id)
$ids[] = $id;
return array_unique($ids);
......
......@@ -22,7 +22,20 @@
class UserGroupLoader extends Storm_Model_Loader {
use Trait_MemoryCleaner;
public function getUsersIdsOf($group) {
$ids = [];
$closure = function($model) use (&$ids) {
$ids[] = $model->getId();
};
Class_UserGroup::usersPaginatedDo($group, $closure);
return $ids;
}
public function getUsersIdsOptimizedOf($group) {
$result = $group->isManual()
? $this->_getManualUserIdsOf($group)
: $this->_getDynamicUserIdsOf($group);
......@@ -500,6 +513,11 @@ class Class_UserGroup extends Storm_Model_Abstract {
}
public function getUsersIdsOptimized() {
return $this->getLoader()->getUsersIdsOptimizedOf($this);
}
public function getUsersPage($page, $items_by_page) {
if ($this->isDynamic())
return $this->getDynamicUsersPage($page, $items_by_page);
......
......@@ -96,7 +96,7 @@ class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControll
->whenCalled('fetchAll')
->with('select user_id as id from user_group_memberships where user_group_id=17')
->answers([])
->answers([ ])
->beStrict());
......@@ -1010,13 +1010,6 @@ class Admin_NewsletterControllerDuplicateActionTest
Class_UserGroup::setMemoryCleaner(function() {});
Zend_Registry::set('sql',
$this->mock()
->whenCalled('fetchAll')
->with('select user_id as id from user_group_memberships where user_group_id=15')
->answers([ ['id' => 1] ])
->beStrict());
$this->dispatch('/admin/newsletter/duplicate/id/1', true);
if ($new_newsletter = Class_Newsletter::findFirstBy(['titre' => 'Nouveautés classique (copie)']))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment