diff options
| author | Developer | 2026-06-27 03:57:56 +0200 |
|---|---|---|
| committer | Developer | 2026-06-27 03:57:56 +0200 |
| commit | a2199efc94bf7ff26e7dd1f3db9e9ae0e4e4cc3a (patch) | |
| tree | 0594634979356849b5639b7118676bb8f7b69a2e /app/Http/Controllers/CinemaController.php | |
| parent | 69408447948657e92ed0c10ad9176bd81a1b22ca (diff) | |
| download | curious-a2199efc94bf7ff26e7dd1f3db9e9ae0e4e4cc3a.tar.gz | |
feat: order cinema movies by Hacker News reference count
Movies are now ranked by how many times their IMDb page is referenced
in HN comments (links table, host=www.imdb.com, field=1, matched via param column).
Uses a correlated subquery for COUNT(*) from links.
Diffstat (limited to 'app/Http/Controllers/CinemaController.php')
| -rw-r--r-- | app/Http/Controllers/CinemaController.php | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/app/Http/Controllers/CinemaController.php b/app/Http/Controllers/CinemaController.php index a526830..160ca33 100644 --- a/app/Http/Controllers/CinemaController.php +++ b/app/Http/Controllers/CinemaController.php @@ -9,6 +9,13 @@ class CinemaController extends Controller { public function cinema() { + $refCounts = DB::connection('cinema') + ->table('links') + ->select('links.param', DB::raw('COUNT(*) as ref_count')) + ->where('links.host', 'www.imdb.com') + ->where('links.field', 1) + ->groupBy('links.param'); + $movies = DB::connection('cinema') ->table('imdb') ->select( @@ -23,13 +30,16 @@ class CinemaController extends Controller 'imdb.poster_url', 'imdb.title_type', 'imdb.runtime_minutes', - 'imdb.has_people' + 'imdb.has_people', + DB::raw('COALESCE(ref.ref_count, 0) as ref_count') ) - ->orderBy('imdb.average_rating', 'desc') - ->orderBy('imdb.num_votes', 'desc') + ->leftJoinSub($refCounts, 'ref', function ($join) { + $join->on('ref.param', '=', 'imdb.imdb_id'); + }) ->whereNotNull('imdb.primary_title') ->whereNotNull('imdb.wiki_article') ->where('imdb.title_type', 'movie') + ->orderBy('ref_count', 'desc') ->simplePaginate(12); $total = DB::connection('cinema') |
