From 5ef7936b48950377bad907f2d05ab2b53df1c931 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:18:23 -0600 Subject: [PATCH 01/59] Update BaseApiController --- app/Http/Controllers/Api/BaseApiController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index a18efa5d2..6fa1073f2 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -59,14 +59,11 @@ class BaseApiController extends Controller $res = $this->fractal->createData($resource)->toArray(); } else { $this->validate($request, [ - 'page' => 'nullable|integer|min:1', + 'page' => 'nullable|integer|min:1|max:10', 'limit' => 'nullable|integer|min:1|max:10' ]); $limit = $request->input('limit') ?? 10; $page = $request->input('page') ?? 1; - if($page > 3) { - return response()->json([]); - } $end = (int) $page * $limit; $start = (int) $end - $limit; $res = NotificationService::get($pid, $start, $end); From 9d7943a9ded7e1368472c9da43145d62cdbba8bb Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:22:35 -0600 Subject: [PATCH 02/59] Add StatusHashtagTransformer --- .../Api/StatusHashtagTransformer.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/Transformer/Api/StatusHashtagTransformer.php diff --git a/app/Transformer/Api/StatusHashtagTransformer.php b/app/Transformer/Api/StatusHashtagTransformer.php new file mode 100644 index 000000000..a0874af7a --- /dev/null +++ b/app/Transformer/Api/StatusHashtagTransformer.php @@ -0,0 +1,35 @@ +hashtag; + $status = $statusHashtag->status; + $profile = $statusHashtag->profile; + + return [ + 'status' => [ + 'type' => $status->type, + 'url' => $status->url(), + 'thumb' => $status->thumb(), + 'sensitive' => (bool) $status->is_nsfw, + 'like_count' => $status->likes_count, + 'share_count' => $status->reblogs_count, + 'user' => [ + 'username' => $profile->username, + 'url' => $profile->url(), + ] + ], + 'hashtag' => [ + 'name' => $hashtag->name, + 'url' => $hashtag->url(), + ] + ]; + } +} From 468a4203ca223fba771688cafac247d41d6b210b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:27:27 -0600 Subject: [PATCH 03/59] Add StatusHashtagService --- app/Services/StatusHashtagService.php | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 app/Services/StatusHashtagService.php diff --git a/app/Services/StatusHashtagService.php b/app/Services/StatusHashtagService.php new file mode 100644 index 000000000..0c5120726 --- /dev/null +++ b/app/Services/StatusHashtagService.php @@ -0,0 +1,73 @@ + 2000 ? 2000 : $stop; + $ids = Redis::zrangebyscore($key, $start, $stop); + if(empty($ids)) { + $ids = self::coldGet($id, $start, $stop); + } + foreach($ids as $statusId) { + $res->push(self::getStatus($statusId, $id)); + } + return $res; + } + + public static function coldGet($id, $start = 0, $stop = 2000) + { + $stop = $stop > 2000 ? 2000 : $stop; + $ids = StatusHashtag::whereHashtagId($id) + ->latest() + ->skip($start) + ->take($stop) + ->pluck('status_id'); + foreach($ids as $key) { + self::set($id, $key); + } + return $ids; + } + + public static function set($key, $val) + { + return Redis::zadd(self::CACHE_KEY . $key, $val, $val); + } + + public static function del($key) + { + return Redis::zrem(self::CACHE_KEY . $key, $val); + } + + public static function count($id) + { + return Redis::zcount(self::CACHE_KEY . $id, '-inf', '+inf'); + } + + public static function getStatus($statusId, $hashtagId) + { + return Cache::remember('pf:services:status-hashtag:post:'.$statusId.':hashtag:'.$hashtagId, now()->addMonths(3), function() use($statusId, $hashtagId) { + $statusHashtag = StatusHashtag::with('profile', 'status', 'hashtag') + ->whereStatusId($statusId) + ->whereHashtagId($hashtagId) + ->first(); + $fractal = new Fractal\Manager(); + $fractal->setSerializer(new ArraySerializer()); + $resource = new Fractal\Resource\Item($statusHashtag, new StatusHashtagTransformer()); + return $fractal->createData($resource)->toArray(); + }); + } +} \ No newline at end of file From 9d55d65b58392b6b780a871355a014247596221e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:38:26 -0600 Subject: [PATCH 04/59] Add StatusHashtagObserver --- app/Observers/StatusHashtagObserver.php | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/Observers/StatusHashtagObserver.php diff --git a/app/Observers/StatusHashtagObserver.php b/app/Observers/StatusHashtagObserver.php new file mode 100644 index 000000000..51832bcb8 --- /dev/null +++ b/app/Observers/StatusHashtagObserver.php @@ -0,0 +1,64 @@ +hashtag_id, $hashtag->status_id); + } + + /** + * Handle the notification "updated" event. + * + * @param \App\Notification $notification + * @return void + */ + public function updated(StatusHashtag $hashtag) + { + StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id); + } + + /** + * Handle the notification "deleted" event. + * + * @param \App\Notification $notification + * @return void + */ + public function deleted(StatusHashtag $hashtag) + { + StatusHashtagService::del($hashtag->hashtag_id, $hashtag->status_id); + } + + /** + * Handle the notification "restored" event. + * + * @param \App\Notification $notification + * @return void + */ + public function restored(StatusHashtag $hashtag) + { + StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id); + } + + /** + * Handle the notification "force deleted" event. + * + * @param \App\Notification $notification + * @return void + */ + public function forceDeleted(StatusHashtag $hashtag) + { + StatusHashtagService::del($hashtag->hashtag_id, $hashtag->status_id); + } +} From dea1e916cf6c39b7638d8977a09f612a3cb2fc52 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:39:00 -0600 Subject: [PATCH 05/59] Add StatusHashtag Observer to AppServiceProvider --- app/Providers/AppServiceProvider.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index cf52e7fd4..6bfe29459 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -5,11 +5,13 @@ namespace App\Providers; use App\Observers\{ AvatarObserver, NotificationObserver, + StatusHashtagObserver, UserObserver }; use App\{ Avatar, Notification, + StatusHashtag, User }; use Auth, Horizon, URL; @@ -31,6 +33,7 @@ class AppServiceProvider extends ServiceProvider Avatar::observe(AvatarObserver::class); Notification::observe(NotificationObserver::class); + StatusHashtag::observe(StatusHashtagObserver::class); User::observe(UserObserver::class); Horizon::auth(function ($request) { From 1980ec025d8c06d48350ded4000f9e3793bfb873 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:41:55 -0600 Subject: [PATCH 06/59] Remove deprecated timeline views --- .../views/timeline/partial/new-form.blade.php | 82 ----------- resources/views/timeline/personal.blade.php | 68 --------- resources/views/timeline/public.blade.php | 59 -------- resources/views/timeline/template.blade.php | 132 ------------------ 4 files changed, 341 deletions(-) delete mode 100644 resources/views/timeline/partial/new-form.blade.php delete mode 100644 resources/views/timeline/personal.blade.php delete mode 100644 resources/views/timeline/public.blade.php delete mode 100644 resources/views/timeline/template.blade.php diff --git a/resources/views/timeline/partial/new-form.blade.php b/resources/views/timeline/partial/new-form.blade.php deleted file mode 100644 index 3dfd37e79..000000000 --- a/resources/views/timeline/partial/new-form.blade.php +++ /dev/null @@ -1,82 +0,0 @@ -
-
-
{{__('Create New Post')}}
-
-
- -
- @csrf - - -
-
- - -
- - Max Size: @maxFileSize(). Supported formats: jpeg, png, gif, bmp. Limited to {{config('pixelfed.max_album_length')}} photos per post. - -
-
- -

- 0 - / - {{config('pixelfed.max_caption_length')}} -

-
-
- -
-
- -
- -
- - Set the visibility of this post. - -
-
- -
- - -
- - Please mark all NSFW and controversial content, as per our content policy. - -
-
- -
- -
- - No filter selected. - -
-
- - -
-
-
- -
-
-
\ No newline at end of file diff --git a/resources/views/timeline/personal.blade.php b/resources/views/timeline/personal.blade.php deleted file mode 100644 index 016727e58..000000000 --- a/resources/views/timeline/personal.blade.php +++ /dev/null @@ -1,68 +0,0 @@ -@extends('layouts.app') - -@push('scripts') - -@endpush - -@section('content') - -
-
- @if ($errors->any()) -
-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif - - @include('timeline.partial.new-form') - -
- @foreach($timeline as $item) - - @include('status.template') - - @endforeach - @if($timeline->count() == 0) -
-
-
-

{{ __('timeline.emptyPersonalTimeline') }}

-
-
-
- @endif -
- - - -
- {{$timeline->links()}} -
- -
-
- - -@endsection diff --git a/resources/views/timeline/public.blade.php b/resources/views/timeline/public.blade.php deleted file mode 100644 index a84e54bd5..000000000 --- a/resources/views/timeline/public.blade.php +++ /dev/null @@ -1,59 +0,0 @@ -@extends('layouts.app') - -@push('scripts') - -@endpush - -@section('content') - -
-
- @if ($errors->any()) -
-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif - - @include('timeline.partial.new-form') - -
- @foreach($timeline as $item) - - @include('status.template') - - @endforeach -
- - - -
- {{$timeline->links()}} -
- -
-
- - -@endsection diff --git a/resources/views/timeline/template.blade.php b/resources/views/timeline/template.blade.php deleted file mode 100644 index 83737a4dd..000000000 --- a/resources/views/timeline/template.blade.php +++ /dev/null @@ -1,132 +0,0 @@ -@extends('layouts.app') - -@section('content') - - - -
-
-
- @if (session('status')) -
- {!! session('status') !!} -
- @endif - @if (session('error')) -
- {!! session('error') !!} -
- @endif - - -
- - @foreach($timeline as $item) - @if(is_null($item->in_reply_to_id)) - @include('status.template') - @endif - @endforeach - - @if($timeline->count() == 0) -
-
-
-

{{ __('timeline.emptyPersonalTimeline') }}

-
-
-
- @endif -
- - - -
- {{$timeline->links()}} -
- -
-
-
- - {{Auth::user()->username}}'s avatar - -
-

@{{Auth::user()->username}}

-

{{Auth::user()->name}}

-
-
- -
- -
- - {{-- --}} - - -
-
-
- -@endsection - -@push('scripts') - -@endpush \ No newline at end of file From 09361db173744c57d6b32c3420dce5bfaa56aeaa Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Jun 2019 22:49:44 -0600 Subject: [PATCH 07/59] Remove deprecated status views --- resources/views/status/show/album.blade.php | 104 ---------------- resources/views/status/show/photo.blade.php | 85 ------------- resources/views/status/show/sidebar.blade.php | 117 ------------------ resources/views/status/show/video.blade.php | 50 -------- resources/views/status/template.blade.php | 2 +- .../views/status/timeline/album.blade.php | 29 ----- .../views/status/timeline/photo.blade.php | 15 --- .../status/timeline/video-album.blade.php | 57 --------- .../views/status/timeline/video.blade.php | 19 --- 9 files changed, 1 insertion(+), 477 deletions(-) delete mode 100644 resources/views/status/show/album.blade.php delete mode 100644 resources/views/status/show/photo.blade.php delete mode 100644 resources/views/status/show/sidebar.blade.php delete mode 100644 resources/views/status/show/video.blade.php delete mode 100644 resources/views/status/timeline/album.blade.php delete mode 100644 resources/views/status/timeline/photo.blade.php delete mode 100644 resources/views/status/timeline/video-album.blade.php delete mode 100644 resources/views/status/timeline/video.blade.php diff --git a/resources/views/status/show/album.blade.php b/resources/views/status/show/album.blade.php deleted file mode 100644 index da71a6dcc..000000000 --- a/resources/views/status/show/album.blade.php +++ /dev/null @@ -1,104 +0,0 @@ -@extends('layouts.app',['title' => $user->username . " posted a photo: " . $status->likes_count . " likes, " . $status->comments_count . " comments" ]) - -@section('content') - -
-
-
-
- -
- -
-
- {{$user->username}} -
-
-
- -
-
-
- @if($status->is_nsfw) -
- -

CW / NSFW / Hidden Media

-

(click to show)

-
- @endif - - @if($status->is_nsfw) -
- @endif -
- @include('status.show.sidebar') -
-
-
- -@endsection - -@push('meta') - - - -@endpush diff --git a/resources/views/status/show/photo.blade.php b/resources/views/status/show/photo.blade.php deleted file mode 100644 index 7c3f34564..000000000 --- a/resources/views/status/show/photo.blade.php +++ /dev/null @@ -1,85 +0,0 @@ -@extends('layouts.app',['title' => $user->username . " posted a photo: " . $status->likes_count . " likes, " . $status->comments_count . " comments" ]) - -@section('content') - -
-
-
-
- -
- -
-
- {{$user->username}} -
-
-
- -
-
-
- @if($status->is_nsfw && $status->media_count == 1) -
- -

CW / NSFW / Hidden Media

-

(click to show)

-
- - - -
- @elseif(!$status->is_nsfw && $status->media_count == 1) -
- -
- @endif -
- @include('status.show.sidebar') -
-
-
- -@endsection - -@push('meta') - - - -@endpush diff --git a/resources/views/status/show/sidebar.blade.php b/resources/views/status/show/sidebar.blade.php deleted file mode 100644 index e524cb98d..000000000 --- a/resources/views/status/show/sidebar.blade.php +++ /dev/null @@ -1,117 +0,0 @@ -
-
- -
- -
-
- {{$user->username}} -
-
-
- -
-
-
-
-
-

- {{$status->profile->username}} - {!! $status->rendered ?? e($status->caption) !!} -

-

View all comments

-
- @foreach($replies as $item) -

- {{ str_limit($item->profile->username, 15)}} - {!! $item->rendered ?? e($item->caption) !!} {{$item->created_at->diffForHumans(null, true, true ,true)}} -

- @endforeach -
-
-
-
-
- @if(Auth::check()) -
- @csrf - - -
-

- - - @endif - -
- @csrf - - -
-
-
- - -
-
- -
diff --git a/resources/views/status/show/video.blade.php b/resources/views/status/show/video.blade.php deleted file mode 100644 index 5babc6f68..000000000 --- a/resources/views/status/show/video.blade.php +++ /dev/null @@ -1,50 +0,0 @@ -@extends('layouts.app',['title' => $user->username . " posted a photo: " . $status->likes_count . " likes, " . $status->comments_count . " comments" ]) - -@section('content') - -
-
-
- -
- @if($status->is_nsfw && $status->media_count == 1) -
- -

CW / NSFW / Hidden Media

-

(click to show)

-
-
- -
-
- @elseif(!$status->is_nsfw && $status->media_count == 1) -
- -
- @endif -
- @include('status.show.sidebar') -
-
-
- -@endsection - -@push('meta') - - - -@endpush diff --git a/resources/views/status/template.blade.php b/resources/views/status/template.blade.php index f9f66f23f..ebdc292fb 100644 --- a/resources/views/status/template.blade.php +++ b/resources/views/status/template.blade.php @@ -91,7 +91,7 @@ likes
-

+

{{$item->profile->username}} diff --git a/resources/views/status/timeline/album.blade.php b/resources/views/status/timeline/album.blade.php deleted file mode 100644 index f606d41c1..000000000 --- a/resources/views/status/timeline/album.blade.php +++ /dev/null @@ -1,29 +0,0 @@ -@if($status->is_nsfw) - -@else -

-@endif \ No newline at end of file diff --git a/resources/views/status/timeline/photo.blade.php b/resources/views/status/timeline/photo.blade.php deleted file mode 100644 index 9009b5d7f..000000000 --- a/resources/views/status/timeline/photo.blade.php +++ /dev/null @@ -1,15 +0,0 @@ -@if($status->is_nsfw) -
- -

CW / NSFW / Hidden Media

-

(click to show)

-
- - - -
-@else -
- -
-@endif \ No newline at end of file diff --git a/resources/views/status/timeline/video-album.blade.php b/resources/views/status/timeline/video-album.blade.php deleted file mode 100644 index 684bd2d34..000000000 --- a/resources/views/status/timeline/video-album.blade.php +++ /dev/null @@ -1,57 +0,0 @@ -@if($status->is_nsfw) - -@else - -@endif \ No newline at end of file diff --git a/resources/views/status/timeline/video.blade.php b/resources/views/status/timeline/video.blade.php deleted file mode 100644 index e0f4245ef..000000000 --- a/resources/views/status/timeline/video.blade.php +++ /dev/null @@ -1,19 +0,0 @@ -@if($status->is_nsfw) -
- -

CW / NSFW / Hidden Media

-

(click to show)

-
-
- -
-
-@else -
- -
-@endif \ No newline at end of file From 7591eadbd19cea17d5fa47f87d33da1dc73452c2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 1 Jul 2019 21:52:29 -0600 Subject: [PATCH 08/59] Update Hashtag limit --- app/Jobs/StatusPipeline/StatusEntityLexer.php | 3 +++ app/Util/Lexer/Extractor.php | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Jobs/StatusPipeline/StatusEntityLexer.php b/app/Jobs/StatusPipeline/StatusEntityLexer.php index ecad11e1e..beda89bd5 100644 --- a/app/Jobs/StatusPipeline/StatusEntityLexer.php +++ b/app/Jobs/StatusPipeline/StatusEntityLexer.php @@ -89,6 +89,9 @@ class StatusEntityLexer implements ShouldQueue $status = $this->status; foreach ($tags as $tag) { + if(mb_strlen($tag) > 124) { + continue; + } DB::transaction(function () use ($status, $tag) { $slug = str_slug($tag, '-', false); $hashtag = Hashtag::firstOrCreate( diff --git a/app/Util/Lexer/Extractor.php b/app/Util/Lexer/Extractor.php index 9e194b068..bcdbba919 100755 --- a/app/Util/Lexer/Extractor.php +++ b/app/Util/Lexer/Extractor.php @@ -264,7 +264,9 @@ class Extractor extends Regex if (preg_match(self::$patterns['end_hashtag_match'], $outer[0])) { continue; } - + if(mb_strlen($hashtag[0]) > 124) { + continue; + } $tags[] = [ 'hashtag' => $hashtag[0], 'indices' => [$start_position, $end_position], From 7ffb4c4a450be192f3563bae898edb191c37cb4f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 1 Jul 2019 23:06:37 -0600 Subject: [PATCH 09/59] Update StatusHashtag model, add media relation --- app/StatusHashtag.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/StatusHashtag.php b/app/StatusHashtag.php index 15e282025..de67ebd6a 100644 --- a/app/StatusHashtag.php +++ b/app/StatusHashtag.php @@ -26,4 +26,16 @@ class StatusHashtag extends Model { return $this->belongsTo(Profile::class); } + + public function media() + { + return $this->hasManyThrough( + Media::class, + Status::class, + 'id', + 'status_id', + 'status_id', + 'id' + ); + } } From 914b0e49657d25ae0c8ea792f3967b92d7ce9a2c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 1 Jul 2019 23:13:43 -0600 Subject: [PATCH 10/59] Update StatusHashtagService --- app/Services/StatusHashtagService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Services/StatusHashtagService.php b/app/Services/StatusHashtagService.php index 0c5120726..4f876a68f 100644 --- a/app/Services/StatusHashtagService.php +++ b/app/Services/StatusHashtagService.php @@ -32,6 +32,7 @@ class StatusHashtagService { { $stop = $stop > 2000 ? 2000 : $stop; $ids = StatusHashtag::whereHashtagId($id) + ->whereHas('media') ->latest() ->skip($start) ->take($stop) From 4f9a88a77f6aafa58f8a731eb184472f70d2b2af Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 1 Jul 2019 23:14:01 -0600 Subject: [PATCH 11/59] Update StatusHashtagTransformer --- app/Transformer/Api/StatusHashtagTransformer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Transformer/Api/StatusHashtagTransformer.php b/app/Transformer/Api/StatusHashtagTransformer.php index a0874af7a..62ccd2c75 100644 --- a/app/Transformer/Api/StatusHashtagTransformer.php +++ b/app/Transformer/Api/StatusHashtagTransformer.php @@ -12,12 +12,13 @@ class StatusHashtagTransformer extends Fractal\TransformerAbstract $hashtag = $statusHashtag->hashtag; $status = $statusHashtag->status; $profile = $statusHashtag->profile; - + return [ 'status' => [ 'type' => $status->type, 'url' => $status->url(), 'thumb' => $status->thumb(), + 'filter' => $status->firstMedia()->filter_class, 'sensitive' => (bool) $status->is_nsfw, 'like_count' => $status->likes_count, 'share_count' => $status->reblogs_count, From 58a19bbf0507cd988565f65ca54e6df71728e351 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2019 00:33:58 -0600 Subject: [PATCH 12/59] Update StatusHashtagTransformer --- .../Api/StatusHashtagTransformer.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/Transformer/Api/StatusHashtagTransformer.php b/app/Transformer/Api/StatusHashtagTransformer.php index 62ccd2c75..afe1712f8 100644 --- a/app/Transformer/Api/StatusHashtagTransformer.php +++ b/app/Transformer/Api/StatusHashtagTransformer.php @@ -15,21 +15,22 @@ class StatusHashtagTransformer extends Fractal\TransformerAbstract return [ 'status' => [ - 'type' => $status->type, - 'url' => $status->url(), - 'thumb' => $status->thumb(), - 'filter' => $status->firstMedia()->filter_class, - 'sensitive' => (bool) $status->is_nsfw, - 'like_count' => $status->likes_count, - 'share_count' => $status->reblogs_count, + 'id' => (int) $status->id, + 'type' => $status->type, + 'url' => $status->url(), + 'thumb' => $status->thumb(), + 'filter' => $status->firstMedia()->filter_class, + 'sensitive' => (bool) $status->is_nsfw, + 'like_count' => $status->likes_count, + 'share_count' => $status->reblogs_count, 'user' => [ 'username' => $profile->username, 'url' => $profile->url(), ] ], 'hashtag' => [ - 'name' => $hashtag->name, - 'url' => $hashtag->url(), + 'name' => $hashtag->name, + 'url' => $hashtag->url(), ] ]; } From 8a47b03a1b21a164e34ad76b15228009b349ec15 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2019 00:34:28 -0600 Subject: [PATCH 13/59] Update StatusHashtagService --- app/Services/StatusHashtagService.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Services/StatusHashtagService.php b/app/Services/StatusHashtagService.php index 4f876a68f..76d0f47e3 100644 --- a/app/Services/StatusHashtagService.php +++ b/app/Services/StatusHashtagService.php @@ -18,9 +18,14 @@ class StatusHashtagService { $res = collect([]); $key = self::CACHE_KEY . $id; $stop = $stop > 2000 ? 2000 : $stop; - $ids = Redis::zrangebyscore($key, $start, $stop); + $ids = Redis::zrevrangebyscore($key, $start, $stop); if(empty($ids)) { - $ids = self::coldGet($id, $start, $stop); + if(self::count($id) == 0) { + $ids = self::coldGet($id, 0, 2000); + $ids = $ids->splice($start, $stop); + } else { + $ids = self::coldGet($id, $start, $stop); + } } foreach($ids as $statusId) { $res->push(self::getStatus($statusId, $id)); From eab5fceb9fb4946f262fe209e61e8e99e8b9f8d2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 4 Jul 2019 20:05:28 -0600 Subject: [PATCH 14/59] Update StatusHashtagService --- app/Services/StatusHashtagService.php | 34 +++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/Services/StatusHashtagService.php b/app/Services/StatusHashtagService.php index 76d0f47e3..1cfcf4290 100644 --- a/app/Services/StatusHashtagService.php +++ b/app/Services/StatusHashtagService.php @@ -13,24 +13,18 @@ class StatusHashtagService { const CACHE_KEY = 'pf:services:status-hashtag:collection:'; - public static function get($id, $start = 0, $stop = 100) + public static function get($id, $page = 1, $stop = 9) { - $res = collect([]); - $key = self::CACHE_KEY . $id; - $stop = $stop > 2000 ? 2000 : $stop; - $ids = Redis::zrevrangebyscore($key, $start, $stop); - if(empty($ids)) { - if(self::count($id) == 0) { - $ids = self::coldGet($id, 0, 2000); - $ids = $ids->splice($start, $stop); - } else { - $ids = self::coldGet($id, $start, $stop); - } - } - foreach($ids as $statusId) { - $res->push(self::getStatus($statusId, $id)); - } - return $res; + return StatusHashtag::whereHashtagId($id) + ->whereHas('media') + ->skip($stop) + ->latest() + ->take(9) + ->pluck('status_id') + ->map(function ($i, $k) use ($id) { + return self::getStatus($i, $id); + }) + ->all(); } public static function coldGet($id, $start = 0, $stop = 2000) @@ -60,7 +54,11 @@ class StatusHashtagService { public static function count($id) { - return Redis::zcount(self::CACHE_KEY . $id, '-inf', '+inf'); + $count = Redis::zcount(self::CACHE_KEY . $id, '-inf', '+inf'); + if(empty($count)) { + $count = StatusHashtag::whereHashtagId($id)->count(); + } + return $count; } public static function getStatus($statusId, $hashtagId) From 6f783cac66b4d3e8ef116dc643ff06f792aea75f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 4 Jul 2019 20:21:20 -0600 Subject: [PATCH 15/59] Update DiscoverController --- app/Http/Controllers/DiscoverController.php | 72 ++++++--------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index bbc8d765c..0a4d67af9 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -17,6 +17,7 @@ use App\Transformer\Api\StatusStatelessTransformer; use League\Fractal; use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Pagination\IlluminatePaginatorAdapter; +use App\Services\StatusHashtagService; class DiscoverController extends Controller { @@ -37,56 +38,9 @@ class DiscoverController extends Controller public function showTags(Request $request, $hashtag) { abort_if(!Auth::check(), 403); - - $tag = Hashtag::whereSlug($hashtag) - ->firstOrFail(); - - $page = 1; - $key = 'discover:tag-'.$tag->id.':page-'.$page; - $keyMinutes = 15; - - $posts = Cache::remember($key, now()->addMinutes($keyMinutes), function() use ($tag, $request) { - $tags = StatusHashtag::select('status_id') - ->whereHashtagId($tag->id) - ->orderByDesc('id') - ->take(48) - ->pluck('status_id'); - - return Status::select( - 'id', - 'uri', - 'caption', - 'rendered', - 'profile_id', - 'type', - 'in_reply_to_id', - 'reblog_of_id', - 'is_nsfw', - 'scope', - 'local', - 'created_at', - 'updated_at' - )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album']) - ->with('media') - ->whereLocal(true) - ->whereNull('uri') - ->whereIn('id', $tags) - ->whereNull('in_reply_to_id') - ->whereNull('reblog_of_id') - ->whereNull('url') - ->whereNull('uri') - ->withCount(['likes', 'comments']) - ->whereIsNsfw(false) - ->whereVisibility('public') - ->orderBy('id', 'desc') - ->get(); - }); - - if($posts->count() == 0) { - abort(404); - } - - return view('discover.tags.show', compact('tag', 'posts')); + $tag = Hashtag::whereSlug($hashtag)->firstOrFail(); + $tagCount = StatusHashtagService::count($tag->id); + return view('discover.tags.show', compact('tag', 'tagCount')); } public function showCategory(Request $request, $slug) @@ -156,7 +110,6 @@ class DiscoverController extends Controller return $res; } - public function loopWatch(Request $request) { abort_if(!Auth::check(), 403); @@ -171,4 +124,21 @@ class DiscoverController extends Controller return response()->json(200); } + + public function getHashtags(Request $request) + { + abort_if(!Auth::check(), 403); + $this->validate($request, [ + 'hashtag' => 'required|alphanum|min:2|max:124', + 'page' => 'nullable|integer|min:1|max:19' + ]); + + $page = $request->input('page') ?? '1'; + $end = $page > 1 ? $page * 9 : 0; + $tag = $request->input('hashtag'); + + $hashtag = Hashtag::whereName($tag)->firstOrFail(); + $res = StatusHashtagService::get($hashtag->id, $page, $end); + return $res; + } } From 9ccada5b0b72f7599cac7cee8d232efc9db305f0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 4 Jul 2019 21:19:29 -0600 Subject: [PATCH 16/59] Update CW for comments --- resources/assets/js/components/PostComponent.vue | 11 +++++++---- resources/assets/js/components/PostMenu.vue | 14 ++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/resources/assets/js/components/PostComponent.vue b/resources/assets/js/components/PostComponent.vue index 8ea58b59c..a0f786fa4 100644 --- a/resources/assets/js/components/PostComponent.vue +++ b/resources/assets/js/components/PostComponent.vue @@ -124,10 +124,13 @@
-
-

This comment may contain sensitive material

-

Show

-
+ + {{truncate(reply.account.username,15)}} + + This comment may contain sensitive material + Show + +

diff --git a/resources/assets/js/components/PostMenu.vue b/resources/assets/js/components/PostMenu.vue index dc5ab0933..b219978ad 100644 --- a/resources/assets/js/components/PostMenu.vue +++ b/resources/assets/js/components/PostMenu.vue @@ -6,8 +6,8 @@