feat(pargar): cap inbound mande/document logs after insert

Keep the newest 2000 success rows per inbound type so dumps stop growing from Pargar webhooks, and store compact document payloads instead of full JSON.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-03 10:19:56 +03:30
co-authored by Cursor
parent c802c67e0d
commit 7e6cd92df4
6 changed files with 323 additions and 5 deletions
+22
View File
@@ -2,6 +2,8 @@
namespace App\Models;
use App\Services\DatabaseLogPruneService;
use App\Services\PargarSyncService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Schema;
@@ -46,6 +48,26 @@ class PargarSyncLog extends Model
return self::$hasConfirmedAtColumn;
}
protected static function booted(): void
{
static::created(function (self $log) {
if (! in_array($log->type, [PargarSyncService::TYPE_MANDE, PargarSyncService::TYPE_DOCUMENT], true)) {
return;
}
dispatch(function () {
if (function_exists('fastcgi_finish_request')) {
@fastcgi_finish_request();
}
try {
app(DatabaseLogPruneService::class)->prunePargarInboundOverflow();
} catch (\Throwable) {
// وب‌هوک پرگار نباید به‌خاطر پاک‌سازی قطع شود
}
})->afterResponse();
});
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);