| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace App\Services\AdminRealtime;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Schema;
- final class AdminRealtimeExchangeList
- {
- public const RESOURCE = 'exchange_list';
- public const CHANNEL = 'admin.operation.exchange_list';
- public const EVENT = 'exchange_list.updated';
- /** Called inside the feed transaction while it holds the state row lock. */
- public static function collectChanges(): void
- {
- if (!Schema::hasTable('admin_exchange_list_changes')) return;
- $buffer = DB::table('admin_exchange_list_changes');
- $ids = (clone $buffer)->orderBy('id')->limit(2000)->pluck('id');
- if ($ids->isEmpty()) return;
- DB::table('admin_realtime_events')->insert([
- 'resource' => self::RESOURCE,
- 'resource_id' => '1',
- 'action' => 'updated',
- 'source' => 'bot-28',
- 'created_at' => now('Asia/Shanghai')->format('Y-m-d H:i:s'),
- ]);
- // Delete only the visible rows. A long transaction can commit a lower ID later.
- $buffer->whereIntegerInRaw('id', $ids->all())->delete();
- }
- }
|