-
-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathMissingPalettes.php
More file actions
62 lines (54 loc) · 1.35 KB
/
MissingPalettes.php
File metadata and controls
62 lines (54 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/
namespace App\Http\Controllers\Admin\Maintenance;
use App\Http\Requests\Maintenance\MaintenanceRequest;
use App\Jobs\ExtractColoursJob;
use App\Models\Configs;
use App\Models\Photo;
use Illuminate\Routing\Controller;
use LycheeVerify\Verify;
/**
* Handles missing palettes for photos.
*/
class MissingPalettes extends Controller
{
/**
* Count photos without a palette.
*
* @return int
*/
public function check(MaintenanceRequest $request): int
{
if (!resolve(Verify::class)->check() || !Configs::getValueAsBool('enable_colour_extractions')) {
return 0;
}
return Photo::query()
->where('type', 'like', 'image/%')
->whereDoesntHave('palette')
->count();
}
/**
* Generate missing palettes for photos in chunks.
*
* @return void
*/
public function do(MaintenanceRequest $request): void
{
if (!resolve(Verify::class)->check() || !Configs::getValueAsBool('enable_colour_extractions')) {
return;
}
$limit = Configs::getValueAsInt('maintenance_processing_limit');
$photos = Photo::with(['size_variants'])
->whereDoesntHave('palette')
->where('type', 'like', 'image/%')
->orderBy('id')
->lazyById($limit);
foreach ($photos as $photo) {
ExtractColoursJob::dispatchSync($photo);
}
}
}