Skip to content

Commit

Permalink
Merge pull request #1451 from HDInnovations/Optimize-MassPM-Function
Browse files Browse the repository at this point in the history
(Optimize) MassPM Function
  • Loading branch information
HDVinnie authored Oct 7, 2020
2 parents 4599211 + e703bc7 commit e7ed0f5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/Staff/MassActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public function create()
*/
public function store(Request $request)
{
$users = User::all();
$banned_group = \cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
$validating_group = \cache()->rememberForever('validating_group', fn () => Group::where('slug', '=', 'validating')->pluck('id'));
$disabled_group = \cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
$pruned_group = \cache()->rememberForever('pruned_group', fn () => Group::where('slug', '=', 'pruned')->pluck('id'));
$users = User::whereNotIn('group_id', [$validating_group[0], $banned_group[0], $disabled_group[0], $pruned_group[0]])->pluck('id');

$subject = $request->input('subject');
$message = $request->input('message');

Expand All @@ -61,8 +66,9 @@ public function store(Request $request)
return \redirect()->route('staff.mass-pm.create')
->withErrors($v->errors());
}
foreach ($users as $user) {
$this->dispatch(new ProcessMassPM(self::SENDER_ID, $user->id, $subject, $message));

foreach ($users as $user_id) {
ProcessMassPM::dispatch(self::SENDER_ID, $user_id, $subject, $message);
}

return \redirect()->route('staff.mass-pm.create')
Expand Down
39 changes: 39 additions & 0 deletions database/migrations/2020_10_07_012129_create_job_batches_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateJobBatchesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->text('failed_job_ids');
$table->text('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('job_batches');
}
}

0 comments on commit e7ed0f5

Please sign in to comment.