-
-
Notifications
You must be signed in to change notification settings - Fork 362
Precompute album sizes. #3922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Precompute album sizes. #3922
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
302c2ab
feat(album-statistics): add album_size_statistics table and model
ildyria 4428d8b
feat(album-statistics): implement RecomputeAlbumSizeJob with propagation
ildyria 298d610
feat(album-statistics): add event listeners for automatic recomputation
ildyria 2bdd58d
test(album-size-statistics): add unit tests for AlbumSizeStatistics m…
ildyria 202ea54
feat(factories): add helper methods to SizeVariantFactory
ildyria 3baa5e7
refactor(statistics): use pre-computed album_size_statistics table
ildyria 014731b
test(album-statistics): add comprehensive tests for RecomputeAlbumSiz…
ildyria a824c18
docs(tasks): mark T-004-14 complete
ildyria fd93bdb
docs(tasks): mark T-004-22, T-004-23, T-004-25, T-004-28 complete
ildyria 3e89905
test(album-statistics): add propagation feature tests
ildyria 1ec30b2
test(album-statistics): add event listener integration tests
ildyria 18f728c
docs(tasks): mark T-004-16, T-004-17, T-004-21 complete
ildyria 7419f7c
feat(commands): add album size statistics management commands
ildyria d865620
docs(tasks): mark command implementation tasks complete
ildyria 62462e1
add album size statistics
ildyria 04d0a3e
fix tests
ildyria 61da698
Merge branch 'master' into album-size-statistics
ildyria 7f1b30b
some fixes
ildyria 49a20f9
fix phpstna
ildyria 4d29708
improve Space speed
ildyria 5705fca
dispatch after import
ildyria 074e012
fix
ildyria 4b34078
fix
ildyria 92e16c3
fix
ildyria c94d0ac
improve
ildyria 20baca6
Merge branch 'master' into album-size-statistics
ildyria 1225c1a
stuff
ildyria 2be87e0
fix error
ildyria 9f62189
fix jobs count
ildyria b191935
fix comments
ildyria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-License-Identifier: MIT | ||
| * Copyright (c) 2017-2018 Tobias Reich | ||
| * Copyright (c) 2018-2026 LycheeOrg. | ||
| */ | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Jobs\RecomputeAlbumSizeJob; | ||
| use App\Models\Album; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Log; | ||
|
|
||
| /** | ||
| * Backfill album size statistics for all albums (T-004-35, T-004-36, FR-004-04). | ||
| * | ||
| * This command dispatches RecomputeAlbumSizeJob for each album to populate | ||
| * the album_size_statistics table with pre-computed size data. | ||
| */ | ||
| class BackfillAlbumSizeStatistics extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'lychee:backfill-album-sizes | ||
| {--dry-run : Preview without making changes} | ||
| {--chunk=1000 : Number of albums to process per batch}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Backfill size statistics (per-variant sizes) for all albums'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle(): int | ||
| { | ||
| $dry_run = $this->option('dry-run'); | ||
| $chunk_size = (int) $this->option('chunk'); | ||
|
|
||
| if ($chunk_size < 1) { | ||
| $this->error('Chunk size must be at least 1'); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| $this->info('Starting album size statistics backfill...'); | ||
| if ($dry_run) { | ||
| $this->warn('DRY RUN MODE - No changes will be made'); | ||
| } | ||
|
|
||
| // Get total count | ||
| $total = Album::query()->count(); | ||
| $this->info("Found {$total} albums to process"); | ||
|
|
||
| if ($total === 0) { | ||
| $this->info('No albums to process'); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| // Process albums ordered by _lft ASC (leaf-to-root order) | ||
| // This ensures child albums are computed before parents | ||
| $bar = $this->output->createProgressBar($total); | ||
| $bar->start(); | ||
|
|
||
| $processed = 0; | ||
|
|
||
| Album::query() | ||
| ->orderBy('_lft', 'asc') | ||
ildyria marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ->chunk($chunk_size, function (\Illuminate\Database\Eloquent\Collection $albums) use ($dry_run, &$processed, $bar): void { | ||
| /** @var Album $album */ | ||
| foreach ($albums as $album) { | ||
| if (!$dry_run) { | ||
| // Dispatch job to recompute size statistics for this album | ||
| RecomputeAlbumSizeJob::dispatch($album->id); | ||
| } | ||
|
|
||
| $processed++; | ||
| $bar->advance(); | ||
|
|
||
| // Log progress at intervals (TE-004-03) | ||
| if ($processed % 100 === 0) { | ||
| $percentage = round(($processed / $bar->getMaxSteps()) * 100, 2); | ||
| Log::info("Backfilled album sizes: {$processed}/{$bar->getMaxSteps()} albums ({$percentage}%)"); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| $bar->finish(); | ||
| $this->newLine(2); | ||
|
|
||
| if ($dry_run) { | ||
| $this->info("DRY RUN: Would have dispatched {$processed} jobs"); | ||
| } else { | ||
| $this->info("Dispatched {$processed} jobs to recompute album size statistics"); | ||
| $this->info('Jobs will be processed by the queue worker'); | ||
| $this->warn('Note: This operation may take some time for large galleries'); | ||
| } | ||
|
|
||
| Log::info("Album size backfill completed: {$processed} albums processed"); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-License-Identifier: MIT | ||
| * Copyright (c) 2017-2018 Tobias Reich | ||
| * Copyright (c) 2018-2026 LycheeOrg. | ||
| */ | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Jobs\RecomputeAlbumSizeJob; | ||
| use App\Models\Album; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Log; | ||
|
|
||
| /** | ||
| * Manually recompute size statistics for a specific album (T-004-39, T-004-40, CLI-004-02). | ||
| * | ||
| * This command is useful for manual recovery when statistics drift out of sync. | ||
| */ | ||
| class RecomputeAlbumSizes extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'lychee:recompute-album-sizes {album_id : The ID of the album to recompute}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Manually recompute size statistics for a specific album'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle(): int | ||
| { | ||
| $album_id = $this->argument('album_id'); | ||
|
|
||
| // Validate album exists | ||
| $album = Album::find($album_id); | ||
| if ($album === null) { | ||
| $this->error("Album with ID '{$album_id}' not found"); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| $this->info("Recomputing size statistics for album: {$album->title} (ID: {$album_id})"); | ||
|
|
||
| // Dispatch job | ||
| RecomputeAlbumSizeJob::dispatch($album_id); | ||
|
|
||
| $this->info('Job dispatched successfully'); | ||
| $this->info('Statistics will be updated by the queue worker'); | ||
|
|
||
| Log::info("Manual recompute triggered for album {$album_id} via CLI"); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.