Skip to content

Commit 4cd1c16

Browse files
committed
remove: tmdb keywords
This extra data isn't useful for anything except being spoiled about the movie/tv. The only usecase its had in the past was searching for anime, but we have a language filter for search now, and filtering by `ja` and `animation` seems to be more reliable than searching for the `anime` keyword.
1 parent 3097949 commit 4cd1c16

33 files changed

+31
-383
lines changed

app/DTO/TorrentSearchFiltersDTO.php

-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public function __construct(
3434
private string $description = '',
3535
private string $mediainfo = '',
3636
private string $uploader = '',
37-
/** @var array<mixed> */
38-
private array $keywords = [],
3937
private ?int $startYear = null,
4038
private ?int $endYear = null,
4139
private ?int $minSize = null,
@@ -149,10 +147,6 @@ final public function toSqlQueryBuilder(): Closure
149147
)
150148
)
151149
)
152-
->when(
153-
$this->keywords !== [],
154-
fn ($query) => $query->whereHas('keywords', fn ($query) => $query->whereIn('name', $this->keywords))
155-
)
156150
->when(
157151
$this->startYear !== null,
158152
fn ($query) => $query
@@ -454,10 +448,6 @@ final public function toMeilisearchFilter(): array
454448
}
455449
}
456450

457-
if ($this->keywords !== []) {
458-
$filters[] = 'keywords IN '.json_encode($this->keywords);
459-
}
460-
461451
if ($this->startYear !== null) {
462452
$filters[] = [
463453
'tmdb_movie.year >= '.$this->startYear,

app/Helpers/TorrentTools.php

-17
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,4 @@ public static function anonymizeMediainfo(string|Stringable|null $mediainfo): ?s
205205

206206
return $mediainfo;
207207
}
208-
209-
/**
210-
* Parse Torrent Keywords.
211-
*
212-
* @return array<string>
213-
*/
214-
public static function parseKeywords(string|Stringable $text): array
215-
{
216-
if ($text instanceof Stringable) {
217-
$text = $text->toString();
218-
}
219-
220-
$keywords = array_filter(array_map('trim', explode(',', $text)));
221-
222-
// unique keywords only (case insensitive)
223-
return array_values(array_intersect_key($keywords, array_unique(array_map('strtolower', $keywords))));
224-
}
225208
}

app/Http/Controllers/API/TorrentController.php

-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use App\Models\Category;
2626
use App\Models\FeaturedTorrent;
2727
use App\Models\IgdbGame;
28-
use App\Models\Keyword;
2928
use App\Models\TmdbMovie;
3029
use App\Models\Torrent;
3130
use App\Models\TorrentFile;
@@ -406,17 +405,6 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
406405
default => null,
407406
};
408407

409-
// Torrent Keywords System
410-
$keywords = [];
411-
412-
foreach (TorrentTools::parseKeywords($request->string('keywords')) as $keyword) {
413-
$keywords[] = ['torrent_id' => $torrent->id, 'name' => $keyword];
414-
}
415-
416-
foreach (collect($keywords)->chunk(intdiv(65_000, 2)) as $keywords) {
417-
Keyword::upsert($keywords->toArray(), ['torrent_id', 'name']);
418-
}
419-
420408
// check for trusted user and update torrent
421409
if ($user->group->is_trusted) {
422410
$appurl = config('app.url');
@@ -585,7 +573,6 @@ public function filter(Request $request): TorrentsResource|\Illuminate\Http\Json
585573
description: $request->filled('description') ? $request->string('description')->toString() : '',
586574
mediainfo: $request->filled('mediainfo') ? $request->string('mediainfo')->toString() : '',
587575
uploader: $request->filled('uploader') ? $request->string('uploader')->toString() : '',
588-
keywords: $request->filled('keywords') ? array_map('trim', explode(',', $request->string('keywords')->toString())) : [],
589576
startYear: $request->filled('startYear') ? $request->integer('startYear') : null,
590577
endYear: $request->filled('endYear') ? $request->integer('endYear') : null,
591578
categoryIds: $request->filled('categories') ? array_map('intval', $request->categories) : [],

app/Http/Controllers/TorrentController.php

-28
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use App\Models\Distributor;
2929
use App\Models\History;
3030
use App\Models\IgdbGame;
31-
use App\Models\Keyword;
3231
use App\Models\TmdbMovie;
3332
use App\Models\Region;
3433
use App\Models\Resolution;
@@ -194,7 +193,6 @@ public function edit(Request $request, int $id): \Illuminate\Contracts\View\Fact
194193
'resolutions' => Resolution::orderBy('position')->get(),
195194
'regions' => Region::orderBy('position')->get(),
196195
'distributors' => Distributor::orderBy('name')->get(),
197-
'keywords' => Keyword::where('torrent_id', '=', $torrent->id)->pluck('name'),
198196
'torrent' => $torrent,
199197
'user' => $user,
200198
]);
@@ -245,21 +243,6 @@ public function update(UpdateTorrentRequest $request, int $id): \Illuminate\Http
245243
Image::make($image_cover->getRealPath())->fit(960, 540)->encode('jpg', 90)->save($path_cover);
246244
}
247245

248-
// Torrent Keywords System
249-
Keyword::where('torrent_id', '=', $torrent->id)->delete();
250-
251-
$keywords = [];
252-
253-
foreach (TorrentTools::parseKeywords($request->string('keywords')) as $keyword) {
254-
$keywords[] = ['torrent_id' => $torrent->id, 'name' => $keyword];
255-
}
256-
257-
foreach (collect($keywords)->chunk(65_000 / 2) as $keywords) {
258-
Keyword::upsert($keywords->toArray(), ['torrent_id', 'name']);
259-
}
260-
261-
$category = $torrent->category;
262-
263246
// Meta
264247

265248
match (true) {
@@ -458,17 +441,6 @@ public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectRe
458441
default => null,
459442
};
460443

461-
// Torrent Keywords System
462-
$keywords = [];
463-
464-
foreach (TorrentTools::parseKeywords($request->string('keywords')) as $keyword) {
465-
$keywords[] = ['torrent_id' => $torrent->id, 'name' => $keyword];
466-
}
467-
468-
foreach (collect($keywords)->chunk(intdiv(65_000, 2)) as $keywords) {
469-
Keyword::upsert($keywords->toArray(), ['torrent_id', 'name']);
470-
}
471-
472444
// check for trusted user and update torrent
473445
if ($user->group->is_trusted && !$request->boolean('mod_queue_opt_in')) {
474446
$appurl = config('app.url');

app/Http/Livewire/SimilarTorrent.php

-4
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ class SimilarTorrent extends Component
6565
#[Url(history: true)]
6666
public string $uploader = '';
6767

68-
#[Url(history: true)]
69-
public string $keywords = '';
70-
7168
#[Url(history: true)]
7269
public ?int $minSize = null;
7370

@@ -286,7 +283,6 @@ final public function torrents(): \Illuminate\Support\Collection
286283
name: $this->name,
287284
description: $this->description,
288285
mediainfo: $this->mediainfo,
289-
keywords: $this->keywords ? array_map('trim', explode(',', $this->keywords)) : [],
290286
uploader: $this->uploader,
291287
episodeNumber: $this->episodeNumber,
292288
seasonNumber: $this->seasonNumber,

app/Http/Livewire/TorrentSearch.php

-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ class TorrentSearch extends Component
5959
#[Url(history: true)]
6060
public string $uploader = '';
6161

62-
#[Url(history: true)]
63-
public string $keywords = '';
64-
6562
#[Url(history: true)]
6663
public ?int $startYear = null;
6764

@@ -341,7 +338,6 @@ final public function filters(): TorrentSearchFiltersDTO
341338
description: $this->description,
342339
mediainfo: $this->mediainfo,
343340
uploader: $this->uploader,
344-
keywords: $this->keywords ? array_map('trim', explode(',', $this->keywords)) : [],
345341
startYear: $this->startYear,
346342
endYear: $this->endYear,
347343
minSize: $this->minSize === null ? null : $this->minSize * $this->minSizeMultiplier,

app/Models/Keyword.php

-61
This file was deleted.

app/Models/Torrent.php

+1-18
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,7 @@ protected function casts(): array
465465
)), JSON_ARRAY())
466466
FROM files
467467
WHERE torrents.id = files.torrent_id
468-
) AS json_files,
469-
(
470-
SELECT COALESCE(JSON_ARRAYAGG(keywords.name), JSON_ARRAY())
471-
FROM keywords
472-
WHERE torrents.id = keywords.torrent_id
473-
) AS json_keywords
468+
) AS json_files
474469
SQL;
475470

476471
protected static function booted(): void
@@ -584,16 +579,6 @@ public function moderated(): \Illuminate\Database\Eloquent\Relations\BelongsTo
584579
]);
585580
}
586581

587-
/**
588-
* Has Many Keywords.
589-
*
590-
* @return \Illuminate\Database\Eloquent\Relations\HasMany<Keyword, $this>
591-
*/
592-
public function keywords(): \Illuminate\Database\Eloquent\Relations\HasMany
593-
{
594-
return $this->hasMany(Keyword::class);
595-
}
596-
597582
/**
598583
* Has Many History.
599584
*
@@ -873,7 +858,6 @@ public function toSearchableArray(): array
873858
'json_freeleech_tokens',
874859
'json_bookmarks',
875860
'json_files',
876-
'json_keywords',
877861
'json_history_seeders',
878862
'json_history_leechers',
879863
'json_history_active',
@@ -944,7 +928,6 @@ public function toSearchableArray(): array
944928
'freeleech_tokens' => json_decode($torrent->json_freeleech_tokens ?? '[]'),
945929
'bookmarks' => json_decode($torrent->json_bookmarks ?? '[]'),
946930
'files' => json_decode($torrent->json_files ?? '[]'),
947-
'keywords' => json_decode($torrent->json_keywords ?? '[]'),
948931
'history_seeders' => json_decode($torrent->json_history_seeders ?? '[]'),
949932
'history_leechers' => json_decode($torrent->json_history_leechers ?? '[]'),
950933
'history_active' => json_decode($torrent->json_history_active ?? '[]'),

app/Services/Tmdb/Client/Movie.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,6 @@ class Movie
184184
* instagram_id: ?string,
185185
* twitter_id: ?string,
186186
* },
187-
* keywords: ?array{
188-
* id: ?int,
189-
* keywords: ?array<
190-
* int<0, max>,
191-
* ?array{
192-
* id: ?int,
193-
* name: ?string,
194-
* },
195-
* >,
196-
* },
197187
* recommendations: ?array{
198188
* page: ?int,
199189
* results: ?array<
@@ -246,7 +236,7 @@ public function __construct(int $id)
246236
->get('https://api.TheMovieDB.org/3/movie/{id}', [
247237
'api_key' => config('api-keys.tmdb'),
248238
'language' => config('app.meta_locale'),
249-
'append_to_response' => 'videos,images,credits,external_ids,keywords,recommendations,alternative_titles',
239+
'append_to_response' => 'videos,images,credits,external_ids,recommendations,alternative_titles',
250240
])
251241
->json();
252242

app/Services/Tmdb/Client/TV.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,6 @@ class TV
244244
* instagram_id: ?string,
245245
* twitter_id: ?string,
246246
* },
247-
* keywords: ?array{
248-
* id: ?int,
249-
* results: ?array<
250-
* int<0, max>,
251-
* ?array{
252-
* id: ?int,
253-
* name: ?string,
254-
* },
255-
* >,
256-
* },
257247
* recommendations: ?array{
258248
* page: ?int,
259249
* results: ?array<
@@ -306,7 +296,7 @@ public function __construct(int $id)
306296
->get('https://api.TheMovieDB.org/3/tv/{id}', [
307297
'api_key' => config('api-keys.tmdb'),
308298
'language' => config('app.meta_locale'),
309-
'append_to_response' => 'videos,images,aggregate_credits,external_ids,keywords,recommendations,alternative_titles',
299+
'append_to_response' => 'videos,images,aggregate_credits,external_ids,recommendations,alternative_titles',
310300
])
311301
->json();
312302

cspell.json

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
"autogroup",
8686
"autoigdb",
8787
"autoimdb",
88-
"autokeywords",
8988
"automal",
9089
"autoreg",
9190
"autores",

database/factories/KeywordFactory.php

-42
This file was deleted.

0 commit comments

Comments
 (0)