mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
indexer: magazines, producers fix duplication issue
This commit is contained in:
parent
a14485f0b6
commit
b51c188770
@ -26,7 +26,7 @@ class CommonIndexer extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Index common endpoints: Producers, Magazines, Anime & Manga Genres';
|
||||
protected $description = 'Index common endpoint metadata: Producers, Magazines';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -70,8 +70,17 @@ class CommonIndexer extends Command
|
||||
echo "Parsed {$itemCount} producers\n";
|
||||
foreach ($results as $i => $item) {
|
||||
$result = DB::table('producers')
|
||||
->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(['request_hash'=>'request:producers:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
],
|
||||
[
|
||||
'mal_id' => $item['mal_id'],
|
||||
'name' => $item['name'],
|
||||
'url' => $item['url'],
|
||||
'count' => $item['count']
|
||||
]
|
||||
);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
|
||||
@ -97,89 +106,17 @@ class CommonIndexer extends Command
|
||||
echo "Parsed {$itemCount} magazines\n";
|
||||
foreach ($results as $i => $item) {
|
||||
$result = DB::table('magazines')
|
||||
->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(['request_hash'=>'request:magazines:'.sha1($item['mal_id'].$item['name'])]+$item);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime Genres
|
||||
*/
|
||||
echo "Indexing Anime Genres...\n";
|
||||
$results = \json_decode(
|
||||
app('SerializerV4')->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
|
||||
)['genres'];
|
||||
|
||||
if (HttpHelper::hasError($results)) {
|
||||
echo "FAILED: {$results->original['error']}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCount = count($results);
|
||||
echo "Parsed {$itemCount} manga genres\n";
|
||||
foreach ($results 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);
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
],
|
||||
[
|
||||
'mal_id' => $item['mal_id'],
|
||||
'name' => $item['name'],
|
||||
'url' => $item['url'],
|
||||
'count' => $item['count']
|
||||
]
|
||||
);
|
||||
echo "Indexing {$i}/{$itemCount} \r";
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,7 @@ class GenreIndexer extends Command
|
||||
$itemCount = count($results['genres']);
|
||||
echo "Parsed {$itemCount} anime genres\n";
|
||||
foreach ($results['genres'] as $i => $item) {
|
||||
$item['count'] = $item['count'];
|
||||
|
||||
$result = DB::table('genres_anime')
|
||||
// ->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -87,7 +84,6 @@ class GenreIndexer extends Command
|
||||
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(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -106,7 +102,6 @@ class GenreIndexer extends Command
|
||||
echo "Parsed {$itemCount} anime themes\n";
|
||||
foreach ($results['themes'] as $i => $item) {
|
||||
$result = DB::table('themes_anime')
|
||||
// ->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -125,7 +120,6 @@ class GenreIndexer extends Command
|
||||
echo "Parsed {$itemCount} anime demographics\n";
|
||||
foreach ($results['demographics'] as $i => $item) {
|
||||
$result = DB::table('demographics_anime')
|
||||
// ->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -162,7 +156,6 @@ class GenreIndexer extends Command
|
||||
echo "Parsed {$itemCount} manga genres\n";
|
||||
foreach ($results['genres'] as $i => $item) {
|
||||
$result = DB::table('genres_manga')
|
||||
// ->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -181,7 +174,6 @@ class GenreIndexer extends Command
|
||||
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(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -200,7 +192,6 @@ class GenreIndexer extends Command
|
||||
echo "Parsed {$itemCount} manga themes\n";
|
||||
foreach ($results['themes'] as $i => $item) {
|
||||
$result = DB::table('themes_manga')
|
||||
// ->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
@ -219,7 +210,6 @@ class GenreIndexer extends Command
|
||||
echo "Parsed {$itemCount} manga demographics\n";
|
||||
foreach ($results['demographics'] as $i => $item) {
|
||||
$result = DB::table('demographics_manga')
|
||||
// ->where('mal_id', $item['mal_id'])
|
||||
->updateOrInsert(
|
||||
[
|
||||
'mal_id' => $item['mal_id']
|
||||
|
Loading…
x
Reference in New Issue
Block a user