HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/iphim.naniguide.com/common/Core/Commands/UpdateSimplePaginateTables.php
<?php

namespace Common\Core\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class UpdateSimplePaginateTables extends Command
{
    protected $signature = 'pagination:optimize';
    protected $description = 'Optimize pagination for large tables.';

    public function handle(): int
    {
        $max = 150000;

        $tables = [];

        collect(DB::select('SHOW TABLES'))
            ->map(function ($val) {
                foreach ($val as $key => $tbl) {
                    return $tbl;
                }
            })
            ->each(function ($table) use ($max, &$tables) {
                if (DB::table($table)->count() > $max) {
                    $tables[] = $table;
                }
            });

        settings()->save([
            'simple_pagination_tables' => implode(',', $tables),
        ]);

        $this->info(
            sprintf(
                'Tables with more than %d rows: %s',
                $max,
                implode(', ', $tables),
            ),
        );

        return Command::SUCCESS;
    }
}