Skip to content

Commit

Permalink
Allow to set APP_FETCHING_BUNCH_SIZE env parameter - closes #4343
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Nov 13, 2024
1 parent 94c1c01 commit b63bad5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public function fetch($mailbox)
$this->line('['.date('Y-m-d H:i:s').'] Fetching: '.($unseen ? 'UNREAD' : 'ALL'));
}

$page_size = (int)config('app.fetching_bunch_size');
foreach ($folders as $folder) {
$this->line('['.date('Y-m-d H:i:s').'] Folder: '.($folder->full_name ?? $folder->name));

Expand All @@ -279,7 +280,7 @@ public function fetch($mailbox)
if ($no_charset) {
$messages_query->setCharset(null);
}
$messages_query->limit(self::PAGE_SIZE, $page);
$messages_query->limit($page_size, $page);

$messages = $messages_query->get();

Expand Down Expand Up @@ -332,7 +333,7 @@ public function fetch($mailbox)
$this->processMessage($message, $message_id, $dest_mailbox, $this->mailboxes);
}
$page++;
} while (count($messages) == self::PAGE_SIZE);
} while (count($messages) == $page_size);
}

$client->disconnect();
Expand Down
11 changes: 11 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@
*/
'since_without_quotes_on_fetching' => env('APP_SINCE_WITHOUT_QUOTES_ON_FETCHING', false),

/*
|--------------------------------------------------------------------------
| Emails are fetched in bunches. The larger the bunch's size the more chances
| to face "Allowed memory size exhausted" error. The smaller its size the more
| connections are made to the mail server and the more time fetching takes.
| https://github.com/freescout-help-desk/freescout/issues/4343
|
|-------------------------------------------------------------------------
*/
'fetching_bunch_size' => env('APP_FETCHING_BUNCH_SIZE', 100),

/*
|--------------------------------------------------------------------------
| Dashboard path.
Expand Down

0 comments on commit b63bad5

Please sign in to comment.