Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 21
DedupDeathmatchProcess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 21
 launch
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 21
1<?php
2
3namespace Qmp\Laravel\Deduplication\Console\Commands;
4
5use Illuminate\Support\Facades\DB;
6use Illuminate\Support\Facades\Schema;
7
8class DedupDeathmatchProcess extends BaseProcessCommand
9{
10    /**
11     * The name and signature of the console command.
12     *
13     * @var string
14     */
15    protected $signature = 'dedup:deathmatch-process {sessionId} {--throw-error : Throw errors if catch}';
16
17    /**
18     * The console command description.
19     *
20     * @var string
21     */
22    protected $description = 'Run dedup test on editor\'s files';
23
24    /**
25     * The entrypoint for the command
26     *
27     * @return void
28     */
29    public function launch(): void
30    {
31        $tempTable = 'sessions_data_temp_' . $this->argument('sessionId');
32        $processesNumber = 6;
33        $count = DB::connection("deduplicationMongo")
34            ->collection($tempTable)->count();
35
36        $this->startTimer('totalInsert');
37        if($count > 0) {
38            $this->createProcessFactory('dedup:deathmatch-chunk ' . $this->argument('sessionId'));
39
40            $tempInt = intdiv($count, $processesNumber);
41            $toTake =  $tempInt === 0 ? $count : $tempInt;
42            $range = $tempInt === 0 ? 0 : range(0, $count, $toTake);
43
44            collect($range)->each(function ($range) use ($toTake) {
45                $options = [
46                    'skip' => $range,
47                    'take' => $toTake,
48                ];
49
50                $this->addProcess($options);
51            });
52
53            $this->startTimer('totalInsert');
54            $this->startProcesses();
55
56        } else {
57            $this->info("Nothing found !");
58        }
59
60        // Remove temp table
61        $this->info("Remove temp collection : $tempTable");
62        //Schema::connection('deduplicationMongo')->dropIfExists($tempTable);
63        $this->info('Insert duration : ' . $this->getTimer('totalInsert'));
64    }
65}