AndrewSimm
Well-known member
I have an article add-on and I am trying to add a feature to alert all users via XF and Push anytime a new article is posted. The code successfully sends alerts but is unable to finish my 20K+ user count. My article ends up not saving as _postSave never completes. How can I process these alerts more efficiently?
	
	
	
		
				
			
		PHP:
	
	 protected function _postSave()
 {
     if ($this->isInsert())
     {
         $extra = [
             'title' => $this->title,
             'article_id' => $this->article_id,
             'username' => $this->User->username
         ];
         $users = \XF::app()
             ->finder('XF:User')
             ->fetch();
         foreach($users as $sendTo)
         {
             if($sendTo->Option->doesReceiveAlert('article', 'article_article'))
             {
                 $alertRepo = $this->repository('XF:UserAlert');
                 $alertRepo->alert(
                     $sendTo,
                     $this->user_id, $this->User->username,
                     'article', $this->article_id,
                     'andrew_article', $extra
                 );
             }
         }
     }
 }