From 7a68ee948a05f53824cc34b0b83d2f5e599375cd Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 26 Dec 2020 20:16:35 -0700 Subject: [PATCH 1/5] Add StatusView model to store views for discover algorithm --- app/Http/Controllers/StatusController.php | 9 +++++ app/StatusView.php | 17 +++++++++ ...12_24_063410_create_status_views_table.php | 35 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 app/StatusView.php create mode 100644 database/migrations/2020_12_24_063410_create_status_views_table.php diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 7b7ddfa4f..c2e573ea9 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -10,6 +10,7 @@ use App\AccountInterstitial; use App\Media; use App\Profile; use App\Status; +use App\StatusView; use App\Transformer\ActivityPub\StatusTransformer; use App\Transformer\ActivityPub\Verb\Note; use App\User; @@ -59,6 +60,14 @@ class StatusController extends Controller } } + if($request->user() && $request->user()->profile_id != $status->profile_id) { + StatusView::firstOrCreate([ + 'status_id' => $status->id, + 'status_profile_id' => $status->profile_id, + 'profile_id' => $request->user()->profile_id + ]); + } + if ($request->wantsJson() && config('federation.activitypub.enabled')) { return $this->showActivityPub($request, $status); } diff --git a/app/StatusView.php b/app/StatusView.php new file mode 100644 index 000000000..569ae2cb4 --- /dev/null +++ b/app/StatusView.php @@ -0,0 +1,17 @@ +bigIncrements('id'); + $table->bigInteger('status_id')->unsigned()->nullable()->index(); + $table->bigInteger('status_profile_id')->unsigned()->nullable()->index(); + $table->bigInteger('profile_id')->unsigned()->nullable()->index(); + $table->unique(['status_id', 'profile_id']); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('status_views'); + } +} From 99331b9b195932617bcfeab662f05be6b092e2ae Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 26 Dec 2020 20:17:22 -0700 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 985580a6c..c69994717 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Add Blurhash encoder ([fad102bf](https://github.com/pixelfed/pixelfed/commit/fad102bf)) - Add autospam feature ([b892bcf0](https://github.com/pixelfed/pixelfed/commit/b892bcf0)) - Add hCaptcha ([082c1ccb](https://github.com/pixelfed/pixelfed/commit/082c1ccb)) +- Add StatusView model to store views for discover algorithm ([7a68ee94](https://github.com/pixelfed/pixelfed/commit/7a68ee94)) ### Updated - Updated PostComponent, fix remote urls ([42716ccc](https://github.com/pixelfed/pixelfed/commit/42716ccc)) From 7d0f7f72228196fdfa07c3db4861d64789fb2a19 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 26 Dec 2020 20:18:13 -0700 Subject: [PATCH 3/5] Add new migrations --- ...5_add_status_profile_id_to_likes_table.php | 36 +++++++++++++++++++ ..._013953_add_text_column_to_media_table.php | 32 +++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 database/migrations/2020_12_25_220825_add_status_profile_id_to_likes_table.php create mode 100644 database/migrations/2020_12_27_013953_add_text_column_to_media_table.php diff --git a/database/migrations/2020_12_25_220825_add_status_profile_id_to_likes_table.php b/database/migrations/2020_12_25_220825_add_status_profile_id_to_likes_table.php new file mode 100644 index 000000000..289b19108 --- /dev/null +++ b/database/migrations/2020_12_25_220825_add_status_profile_id_to_likes_table.php @@ -0,0 +1,36 @@ +bigInteger('status_profile_id')->nullable()->unsigned()->index()->after('status_id'); + $table->boolean('is_comment')->nullable()->index()->after('status_profile_id'); + $table->dropColumn('flagged'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('likes', function (Blueprint $table) { + $table->dropColumn('status_profile_id'); + $table->dropColumn('is_comment'); + $table->boolean('flagged')->default(false); + }); + } +} diff --git a/database/migrations/2020_12_27_013953_add_text_column_to_media_table.php b/database/migrations/2020_12_27_013953_add_text_column_to_media_table.php new file mode 100644 index 000000000..04a91abea --- /dev/null +++ b/database/migrations/2020_12_27_013953_add_text_column_to_media_table.php @@ -0,0 +1,32 @@ +text('cdn_url')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('media', function (Blueprint $table) { + $table->string('cdn_url')->nullable()->change(); + }); + } +} From 799a4cba125e5839234d05eadbda514287d08b61 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 26 Dec 2020 20:18:48 -0700 Subject: [PATCH 4/5] Update LikeController, store status_profile_id and is_comment attributes --- app/Http/Controllers/LikeController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Http/Controllers/LikeController.php b/app/Http/Controllers/LikeController.php index 601286179..df6ed286b 100644 --- a/app/Http/Controllers/LikeController.php +++ b/app/Http/Controllers/LikeController.php @@ -43,6 +43,15 @@ class LikeController extends Controller if($like->wasRecentlyCreated == true) { $count++; $status->likes_count = $count; + $like->status_profile_id = $status->profile_id; + $like->is_comment = in_array($status->type, [ + 'photo', + 'photo:album', + 'video', + 'video:album', + 'photo:video:album' + ]) == false; + $like->save(); $status->save(); LikePipeline::dispatch($like); } From b74e14c4e5daa8e32f87993945c17c88ff2942ed Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 26 Dec 2020 20:28:12 -0700 Subject: [PATCH 5/5] Update SiteController --- app/Http/Controllers/SiteController.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index f6344f371..c93a5e68f 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -62,20 +62,16 @@ class SiteController extends Controller public function about() { - return Cache::remember('site:about', now()->addHours(12), function() { - app()->setLocale('en'); - $page = Page::whereSlug('/site/about')->whereActive(true)->first(); - $stats = [ - 'posts' => Status::whereLocal(true)->count(), + $page = Page::whereSlug('/site/about')->whereActive(true)->first(); + $stats = Cache::remember('site:about:stats-v1', now()->addHours(12), function() { + return [ + 'posts' => Status::count(), 'users' => User::whereNull('status')->count(), 'admin' => User::whereIsAdmin(true)->first() ]; - if($page) { - return View::make('site.about-custom')->with(compact('page', 'stats'))->render(); - } else { - return View::make('site.about')->with(compact('stats'))->render(); - } }); + $path = $page ? 'site.about-custom' : 'site.about'; + return view($path, compact('page', 'stats')); } public function language()