If I understand correctly, the parseImport() method receives a file but you don't actually save it as such. Instead you convert that into a huge array/object, which then save as json in one CsvData record, in a longtext field, right ?
If that's the case, I don't see how it can work with a million record csv. Nevermind the overehead converting the csv file into some array/object, then converting that into json. That massive record has to be saved on the database, just later on be retrieved.
Personally, I would save the file as csv in the filesystem, with some random name to avoid be overwritten or something like that. The CsvData model will store the path to such file, instead of the actual data.
When it's time to process the file, don't load the entire thing into memory. Use a stream
$stream = fopen($csvData->path, 'r');
if ($stream) {
while (! feof($stream)) {
$line = fgets($stream);
// parse each line and do stuff
}
fclose($stream);
}
Though with a million record dataset the process time to create all those contacts might be an issue
Maybe you should explore the posibility of processing such file with a job in the background