Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Actions/Diagnostics/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use App\Actions\Diagnostics\Pipes\Checks\PHPVersionCheck;
use App\Actions\Diagnostics\Pipes\Checks\PlaceholderExistsCheck;
use App\Actions\Diagnostics\Pipes\Checks\SmallMediumExistsCheck;
use App\Actions\Diagnostics\Pipes\Checks\StatisticsIntegrityCheck;
use App\Actions\Diagnostics\Pipes\Checks\SupporterCheck;
use App\Actions\Diagnostics\Pipes\Checks\TimezoneCheck;
use App\Actions\Diagnostics\Pipes\Checks\UpdatableCheck;
Expand Down Expand Up @@ -65,6 +66,7 @@ class Errors
CacheTemporaryUrlCheck::class,
SupporterCheck::class,
ImagickPdfCheck::class,
StatisticsIntegrityCheck::class,
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Actions\Diagnostics\Pipes\Checks;

use App\Contracts\DiagnosticPipe;
use App\DTO\DiagnosticData;
use App\Http\Resources\Diagnostics\StatisticsCheckResource;
use App\Models\Configs;
use Illuminate\Support\Facades\DB;

/**
* Check whether or not there are photos or albums without statistics.
*/
class StatisticsIntegrityCheck implements DiagnosticPipe
{
/**
* {@inheritDoc}
*/
public function handle(array &$data, \Closure $next): array
{
$check = $this->get();

if ($check->missing_albums > 0) {
$data[] = DiagnosticData::warn(sprintf('There are %d albums without statistics.', $check->missing_albums), self::class,
['Go to the maintenance page to fix this.']);
}

if ($check->missing_albums > 0) {
$data[] = DiagnosticData::warn(sprintf('There are %d photos without statistics.', $check->missing_photos), self::class,
['Go to the maintenance page to fix this.']);
}

return $next($data);
}

public function get(): StatisticsCheckResource
{
// Just skip the check, we don't care.
if (!Configs::getValueAsBool('metrics_enabled')) {
return new StatisticsCheckResource(0, 0);
}

$num_albums = DB::table('base_albums')->leftJoin('statistics', 'base_albums.id', '=', 'statistics.album_id')
->whereNull('statistics.id')
->count();
$num_photos = DB::table('photos')->leftJoin('statistics', 'photos.id', '=', 'statistics.photo_id')
->whereNull('statistics.id')
->count();

return new StatisticsCheckResource($num_albums, $num_photos);
}
}
56 changes: 56 additions & 0 deletions app/Http/Controllers/Admin/Maintenance/StatisticsCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Http\Controllers\Admin\Maintenance;

use App\Actions\Diagnostics\Pipes\Checks\StatisticsIntegrityCheck;
use App\Http\Requests\Maintenance\MaintenanceRequest;
use App\Http\Resources\Diagnostics\StatisticsCheckResource;
use App\Models\Configs;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;

/**
* We may miss some statistics because of generation problem.
* This module aims to solve this issue.
*/
class StatisticsCheck extends Controller
{
public function __construct(
private StatisticsIntegrityCheck $check,
) {
}

/**
* Create th emissing statistics.
*
* @return StatisticsCheckResource
*/
public function do(MaintenanceRequest $request): StatisticsCheckResource
{
// Just skip the check, we don't care.
if (!Configs::getValueAsBool('metrics_enabled')) {
return new StatisticsCheckResource(0, 0);
}

DB::statement('INSERT INTO statistics (photo_id) SELECT photos.id FROM photos LEFT OUTER JOIN statistics ON photos.id = photo_id WHERE statistics.id IS NULL');
DB::statement('INSERT INTO statistics (album_id) SELECT base_albums.id FROM base_albums LEFT OUTER JOIN statistics ON base_albums.id = album_id WHERE statistics.id IS NULL');

return $this->check->get();
}

/**
* Check how many statistics are missing for photos and albums.
*
* @return StatisticsCheckResource
*/
public function check(MaintenanceRequest $request): StatisticsCheckResource
{
return $this->check->get();
}
}
22 changes: 22 additions & 0 deletions app/Http/Resources/Diagnostics/StatisticsCheckResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Http\Resources\Diagnostics;

use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript()]
class StatisticsCheckResource extends Data
{
public function __construct(
public int $missing_photos,
public int $missing_albums,
) {
}
}
6 changes: 5 additions & 1 deletion app/Http/Resources/Models/PhotoStatisticsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function __construct(
) {
}

public static function fromModel(Statistics $stats): PhotoStatisticsResource
public static function fromModel(Statistics|null $stats): PhotoStatisticsResource|null
{
if ($stats === null) {
return null;
}

return new self(
$stats->visit_count,
$stats->download_count,
Expand Down
1 change: 1 addition & 0 deletions app/Metadata/Cache/RouteCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct()
'api/v2/Maintenance::update' => false,
'api/v2/Maintenance::countDuplicates' => false,
'api/v2/Maintenance::searchDuplicates' => false,
'api/v2/Maintenance::statisticsIntegrity' => false,

'api/v2/Map' => new RouteCacheConfig(tag: CacheTag::GALLERY, user_dependant: true, extra: [RequestAttribute::ALBUM_ID_ATTRIBUTE]),
'api/v2/Map::provider' => new RouteCacheConfig(tag: CacheTag::SETTINGS),
Expand Down
6 changes: 6 additions & 0 deletions lang/ar/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
'update-button' => '',
'no-pending-updates' => '',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => '',
'description' => '',
Expand Down
6 changes: 6 additions & 0 deletions lang/cz/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/de/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'Keine Updates verfügbar.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Cache leeren',
'description' => 'Leeren Sie den Cache jedes Benutzers, um Ungültigkeitsprobleme zu lösen.',
Expand Down
6 changes: 6 additions & 0 deletions lang/el/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/en/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/es/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/fr/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
'update-button' => 'Mettre à jour',
'no-pending-updates' => 'Aucune mise à jour en attente.',
],
'statistics-check' => [
'title' => 'Check de l’intégrité des Statistiques',
'missing_photos' => '%d statistiques de photos manquantes.',
'missing_albums' => '%d statistiques d’albums manquantes.',
'button' => 'Créer les statistiques manquantes',
],
'flush-cache' => [
'title' => 'Vider le cache',
'description' => 'Vider le cache de tous les utilisateurs pour résoudre les problèmes d’invalidation.',
Expand Down
6 changes: 6 additions & 0 deletions lang/hu/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/it/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/ja/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
'update-button' => '更新',
'no-pending-updates' => '保留中の更新はありません',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/nl/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/no/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/pl/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Aktualizacja',
'no-pending-updates' => 'Brak oczekujących aktualizacji.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Opróżnianie pamięci podręcznej',
'description' => 'Opróżnianie pamięci podręcznej każdego użytkownika w celu rozwiązania problemów z unieważnianiem.',
Expand Down
6 changes: 6 additions & 0 deletions lang/pt/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/ru/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
'update-button' => 'Обновить',
'no-pending-updates' => 'Нет ожидающих обновлений.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Очистить кэш',
'description' => 'Очистить кэш каждого пользователя для решения проблем с устаревшими данными.',
Expand Down
6 changes: 6 additions & 0 deletions lang/sk/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
6 changes: 6 additions & 0 deletions lang/sv/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
'update-button' => 'Update',
'no-pending-updates' => 'No pending update.',
],
'statistics-check' => [
'title' => 'Statistics integrity Check',
'missing_photos' => '%d photo statistics missing.',
'missing_albums' => '%d album statistics missing.',
'button' => 'Create missing',
],
'flush-cache' => [
'title' => 'Flush Cache',
'description' => 'Flush the cache of every user to solve invalidation problems.',
Expand Down
Loading