messages implemented
This commit is contained in:
25
app/Jobs/DeleteMessageFromIndexJob.php
Normal file
25
app/Jobs/DeleteMessageFromIndexJob.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Message;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DeleteMessageFromIndexJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 3;
|
||||
public int $timeout = 30;
|
||||
|
||||
public function __construct(public readonly int $messageId) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
Message::query()->whereKey($this->messageId)->unsearchable();
|
||||
}
|
||||
}
|
||||
36
app/Jobs/IndexMessageJob.php
Normal file
36
app/Jobs/IndexMessageJob.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Message;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class IndexMessageJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 3;
|
||||
public int $timeout = 30;
|
||||
|
||||
public function __construct(public readonly int $messageId) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$message = Message::with(['sender:id,username', 'attachments'])->find($this->messageId);
|
||||
|
||||
if (! $message) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $message->shouldBeSearchable()) {
|
||||
$message->unsearchable();
|
||||
return;
|
||||
}
|
||||
|
||||
$message->searchable();
|
||||
}
|
||||
}
|
||||
42
app/Jobs/IndexUserJob.php
Normal file
42
app/Jobs/IndexUserJob.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Queued job: index (or re-index) a single User in Meilisearch.
|
||||
* Dispatched by UserStatsService whenever stats change.
|
||||
*/
|
||||
class IndexUserJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 3;
|
||||
public int $timeout = 30;
|
||||
|
||||
public function __construct(public readonly int $userId) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$user = User::with('statistics')->find($this->userId);
|
||||
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $user->shouldBeSearchable()) {
|
||||
$user->unsearchable();
|
||||
return;
|
||||
}
|
||||
|
||||
$user->searchable();
|
||||
}
|
||||
}
|
||||
36
app/Jobs/RecomputeUserStatsJob.php
Normal file
36
app/Jobs/RecomputeUserStatsJob.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\UserStatsService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Recomputes user_statistics for a batch of user IDs.
|
||||
* Dispatched by RecomputeUserStatsCommand when --queue is set.
|
||||
*/
|
||||
class RecomputeUserStatsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 2;
|
||||
public int $timeout = 300;
|
||||
|
||||
/**
|
||||
* @param array<int> $userIds
|
||||
*/
|
||||
public function __construct(public readonly array $userIds) {}
|
||||
|
||||
public function handle(UserStatsService $statsService): void
|
||||
{
|
||||
foreach ($this->userIds as $userId) {
|
||||
$statsService->recomputeUser((int) $userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user