I need to run a query in a console command:
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Jobs\SendVaccationEmail;
class ProcessDbResult extends Command
{
protected $signature = "process:entries";
protected $description = "Bulk Process of results";
public function handle()
{
$sql = "
SELECT DISTINCT
user_id
from
(Select user_id from travels where destination = "Bahamas") as bahamas_vac
LEFT JOIN (Select user_id from travels where destination <> "Bahamas") as non_bahamas_vac ON bahamas_vac.user_id = non_bahamas_vac.user_id
WHERE
non_bahamas_vac.user_id = NULL
";
$results = DB:select($sql);
foreach($results as $result){
SendVaccationEmail::dispatch($result);
}
}
}
But expect the results to be rather large ~ 100.000 records, therefore in order to save memory consumption, I want somehow the database results to be streamed instead being fetched on one go.
What I actually want to do is:
Meaning I do not want to wait for results to be returned but once I have the first result I want to begin to process it.
Is somehow feasible Using laravel? I'm stuck with laravel 5.8.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/licHXJE
via IFTTT
Aucun commentaire:
Enregistrer un commentaire