Skip to content

Commit

Permalink
Allow increased memory limits to be set via config
Browse files Browse the repository at this point in the history
  • Loading branch information
mbardelmeijer committed Aug 30, 2023
1 parent 843d5d6 commit 7e729c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/excel-to-google-sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
* instead of a file path.
*/
'service_account_credentials_json' => storage_path('secrets/google-service-account.json'),

/**
* When set, the given memory limit will be used for the duration of the export.
*/
'memory_limit' => null,
];
1 change: 1 addition & 0 deletions src/Commands/PushAllExportsToGoogleSheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Enflow\LaravelExcelToGoogleSheet\GoogleSheetPusher;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Throwable;

class PushAllExportsToGoogleSheets extends Command
Expand Down
15 changes: 15 additions & 0 deletions src/Commands/PushExportToGoogleSheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function handle(GoogleSheetPusher $googleSheetPusher): int

$this->warn("Pushing {$export} to Google Sheets...");

$this->increaseMemoryLimitIfRequired();

/** @var \Enflow\LaravelExcelToGoogleSheet\ExportableToGoogleSheet $exporter */
$exporter = new $export();

Expand All @@ -58,4 +60,17 @@ private function askExport(): ?string

return $exports[$exportName] ?? null;
}

private function increaseMemoryLimitIfRequired(): void
{
$memoryLimit = config('excel-to-google-sheet.memory_limit');
if ($memoryLimit === null) {
return;
}

// `phpoffice/phpspreadsheet` uses a lot of memory while processing the export.
// We'll allow the memory limit to be configured in the config.
// TODO: search for a more long term solution.
ini_set('memory_limit', $memoryLimit);
}
}

0 comments on commit 7e729c1

Please sign in to comment.