From 01e29b06d54151b3ac750cf484cc32de1d9b784e Mon Sep 17 00:00:00 2001 From: Irfan Date: Sat, 13 Nov 2021 04:53:39 +0500 Subject: [PATCH] update & separate genre indexer: `indexer:genres` --- .../Commands/Indexer/CommonIndexer.php | 33 +++- app/Console/Commands/Indexer/GenreIndexer.php | 158 ++++++++++++++++++ app/Console/Kernel.php | 8 +- composer.lock | 8 +- 4 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 app/Console/Commands/Indexer/GenreIndexer.php diff --git a/app/Console/Commands/Indexer/CommonIndexer.php b/app/Console/Commands/Indexer/CommonIndexer.php index 2db6a6d..25924b6 100644 --- a/app/Console/Commands/Indexer/CommonIndexer.php +++ b/app/Console/Commands/Indexer/CommonIndexer.php @@ -113,22 +113,49 @@ class CommonIndexer extends Command 'json' ), true - )['genres']; + ); if (HttpHelper::hasError($results)) { echo "FAILED: {$results->original['error']}\n"; return; } - $itemCount = count($results); + $itemCount = count($results['genres']); echo "Parsed {$itemCount} anime genres\n"; - foreach ($results as $i => $item) { + foreach ($results['genres'] as $i => $item) { $result = DB::table('genres_anime') ->where('mal_id', $item['mal_id']) ->updateOrInsert(['request_hash'=>'request:anime_genres:'.sha1($item['mal_id'].$item['name'])]+$item); echo "Indexing {$i}/{$itemCount} \r"; } + $itemCount = count($results['explicit_genres']); + echo "Parsed {$itemCount} anime explicit_genres\n"; + foreach ($results['explicit_genres'] as $i => $item) { + $result = DB::table('explicit_genres_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_explicit_genres:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['themes']); + echo "Parsed {$itemCount} anime themes\n"; + foreach ($results['themes'] as $i => $item) { + $result = DB::table('themes_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_themes:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['demographics']); + echo "Parsed {$itemCount} anime demographics\n"; + foreach ($results['demographics'] as $i => $item) { + $result = DB::table('demographics_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_demographics:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + /** * Manga Genres */ diff --git a/app/Console/Commands/Indexer/GenreIndexer.php b/app/Console/Commands/Indexer/GenreIndexer.php new file mode 100644 index 0000000..b8d8bbc --- /dev/null +++ b/app/Console/Commands/Indexer/GenreIndexer.php @@ -0,0 +1,158 @@ +serialize( + app('JikanParser') + ->getAnimeGenres(new AnimeGenresRequest()), + 'json' + ), + true + ); + + if (HttpHelper::hasError($results)) { + echo "FAILED: {$results->original['error']}\n"; + return; + } + + $itemCount = count($results['genres']); + echo "Parsed {$itemCount} anime genres\n"; + foreach ($results['genres'] as $i => $item) { + $result = DB::table('genres_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_genres:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['explicit_genres']); + echo "Parsed {$itemCount} anime explicit_genres\n"; + foreach ($results['explicit_genres'] as $i => $item) { + $result = DB::table('explicit_genres_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_explicit_genres:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['themes']); + echo "Parsed {$itemCount} anime themes\n"; + foreach ($results['themes'] as $i => $item) { + $result = DB::table('themes_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_themes:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['demographics']); + echo "Parsed {$itemCount} anime demographics\n"; + foreach ($results['demographics'] as $i => $item) { + $result = DB::table('demographics_anime') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:anime_demographics:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + /** + * Manga Genres + */ + echo "Indexing Manga Genres...\n"; + $results = \json_decode( + app('SerializerV4')->serialize( + app('JikanParser') + ->getMangaGenres(new MangaGenresRequest()), + 'json' + ), + true + ); + + if (HttpHelper::hasError($results)) { + echo "FAILED: {$results->original['error']}\n"; + return; + } + + $itemCount = count($results['genres']); + echo "Parsed {$itemCount} manga genres\n"; + foreach ($results['genres'] as $i => $item) { + $result = DB::table('genres_manga') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:manga_genres:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['explicit_genres']); + echo "Parsed {$itemCount} manga explicit_genres\n"; + foreach ($results['explicit_genres'] as $i => $item) { + $result = DB::table('explicit_genres_manga') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:manga_explicit_genres:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['themes']); + echo "Parsed {$itemCount} manga themes\n"; + foreach ($results['themes'] as $i => $item) { + $result = DB::table('themes_manga') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:manga_themes:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + $itemCount = count($results['demographics']); + echo "Parsed {$itemCount} manga demographics\n"; + foreach ($results['demographics'] as $i => $item) { + $result = DB::table('demographics_manga') + ->where('mal_id', $item['mal_id']) + ->updateOrInsert(['request_hash'=>'request:manga_demographics:'.sha1($item['mal_id'].$item['name'])]+$item); + echo "Indexing {$i}/{$itemCount} \r"; + } + + + echo str_pad("Indexing complete", 10).PHP_EOL; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7bcc434..653aab4 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -12,8 +12,8 @@ use App\Console\Commands\Indexer\AnimeIndexer; use App\Console\Commands\Indexer\AnimeScheduleIndexer; use App\Console\Commands\Indexer\CommonIndexer; use App\Console\Commands\Indexer\CurrentSeasonIndexer; +use App\Console\Commands\Indexer\GenreIndexer; use App\Console\Commands\Indexer\MangaIndexer; -use App\Console\Commands\Indexer\ScheduleIndexer; use App\Console\Commands\ManageMicrocaching; use App\Console\Commands\ModifyCacheDriver; use App\Console\Commands\ModifyCacheMethod; @@ -38,7 +38,8 @@ class Kernel extends ConsoleKernel CurrentSeasonIndexer::class, ManageMicrocaching::class, AnimeIndexer::class, - MangaIndexer::class + MangaIndexer::class, + GenreIndexer::class ]; /** @@ -61,5 +62,8 @@ class Kernel extends ConsoleKernel // Update common indexes daily $schedule->command('indexer:common') ->daily(); + + $schedule->command('indexer:genres') + ->daily(); } } diff --git a/composer.lock b/composer.lock index f0e4bcc..6e74613 100755 --- a/composer.lock +++ b/composer.lock @@ -2931,12 +2931,12 @@ "source": { "type": "git", "url": "https://github.com/jikan-me/jikan.git", - "reference": "77a6ea88472aad8ab3f6a7ae485341fb4c7c6c6e" + "reference": "74209b3b675bdbfc09fc5e6d53cbafdc89a04cf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jikan-me/jikan/zipball/77a6ea88472aad8ab3f6a7ae485341fb4c7c6c6e", - "reference": "77a6ea88472aad8ab3f6a7ae485341fb4c7c6c6e", + "url": "https://api.github.com/repos/jikan-me/jikan/zipball/74209b3b675bdbfc09fc5e6d53cbafdc89a04cf4", + "reference": "74209b3b675bdbfc09fc5e6d53cbafdc89a04cf4", "shasum": "" }, "require": { @@ -2985,7 +2985,7 @@ "type": "patreon" } ], - "time": "2021-11-12T22:51:32+00:00" + "time": "2021-11-12T23:18:34+00:00" }, { "name": "jms/metadata",