Merge pull request #2837 from pixelfed/staging

Staging
This commit is contained in:
daniel 2021-07-02 01:45:34 -06:00 committed by GitHub
commit 2158b2ffdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 142 additions and 101 deletions

View file

@ -38,6 +38,7 @@
- Updated Network Timeline, use existing Timeline component. ([0deaafc0](https://github.com/pixelfed/pixelfed/commit/0deaafc0)) - Updated Network Timeline, use existing Timeline component. ([0deaafc0](https://github.com/pixelfed/pixelfed/commit/0deaafc0))
- Updated PostComponent, show like count to owner using MomentUI. ([e9c46bab](https://github.com/pixelfed/pixelfed/commit/e9c46bab)) - Updated PostComponent, show like count to owner using MomentUI. ([e9c46bab](https://github.com/pixelfed/pixelfed/commit/e9c46bab))
- Updated ContextMenu, add missing statusUrl method. ([3cffdb11](https://github.com/pixelfed/pixelfed/commit/3cffdb11)) - Updated ContextMenu, add missing statusUrl method. ([3cffdb11](https://github.com/pixelfed/pixelfed/commit/3cffdb11))
- Updated PublicApiController, add LikeService to Network timeline. ([82895591](https://github.com/pixelfed/pixelfed/commit/82895591))
- ([](https://github.com/pixelfed/pixelfed/commit/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0) ## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0)

View file

@ -26,6 +26,7 @@ use App\Transformer\Api\{
}; };
use App\Services\{ use App\Services\{
AccountService, AccountService,
LikeService,
PublicTimelineService, PublicTimelineService,
StatusService, StatusService,
SnowflakeService, SnowflakeService,
@ -527,8 +528,10 @@ class PublicApiController extends Controller
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit($limit) ->limit($limit)
->get() ->get()
->map(function($s) { ->map(function($s) use ($user) {
return StatusService::get($s->id); $status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status;
}); });
$res = $timeline->toArray(); $res = $timeline->toArray();
} else { } else {
@ -545,8 +548,10 @@ class PublicApiController extends Controller
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit($limit) ->limit($limit)
->get() ->get()
->map(function($s) { ->map(function($s) use ($user) {
return StatusService::get($s->id); $status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status;
}); });
$res = $timeline->toArray(); $res = $timeline->toArray();
} }

View file

@ -0,0 +1,64 @@
<?php
namespace App\Observers;
use App\Like;
use App\Services\LikeService;
class LikeObserver
{
/**
* Handle the Like "created" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function created(Like $like)
{
LikeService::add($like->profile_id, $like->status_id);
}
/**
* Handle the Like "updated" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function updated(Like $like)
{
//
}
/**
* Handle the Like "deleted" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function deleted(Like $like)
{
LikeService::remove($like->profile_id, $like->status_id);
}
/**
* Handle the Like "restored" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function restored(Like $like)
{
LikeService::add($like->profile_id, $like->status_id);
}
/**
* Handle the Like "force deleted" event.
*
* @param \App\Models\Like $like
* @return void
*/
public function forceDeleted(Like $like)
{
LikeService::remove($like->profile_id, $like->status_id);
}
}

View file

@ -4,6 +4,7 @@ namespace App\Providers;
use App\Observers\{ use App\Observers\{
AvatarObserver, AvatarObserver,
LikeObserver,
NotificationObserver, NotificationObserver,
ModLogObserver, ModLogObserver,
ProfileObserver, ProfileObserver,
@ -13,6 +14,7 @@ use App\Observers\{
}; };
use App\{ use App\{
Avatar, Avatar,
Like,
Notification, Notification,
ModLog, ModLog,
Profile, Profile,
@ -37,36 +39,18 @@ class AppServiceProvider extends ServiceProvider
{ {
URL::forceScheme('https'); URL::forceScheme('https');
Schema::defaultStringLength(191); Schema::defaultStringLength(191);
Paginator::useBootstrap(); Paginator::useBootstrap();
Avatar::observe(AvatarObserver::class); Avatar::observe(AvatarObserver::class);
Like::observe(LikeObserver::class);
Notification::observe(NotificationObserver::class); Notification::observe(NotificationObserver::class);
ModLog::observe(ModLogObserver::class); ModLog::observe(ModLogObserver::class);
Profile::observe(ProfileObserver::class); Profile::observe(ProfileObserver::class);
StatusHashtag::observe(StatusHashtagObserver::class); StatusHashtag::observe(StatusHashtagObserver::class);
User::observe(UserObserver::class); User::observe(UserObserver::class);
UserFilter::observe(UserFilterObserver::class); UserFilter::observe(UserFilterObserver::class);
Horizon::auth(function ($request) { Horizon::auth(function ($request) {
return Auth::check() && $request->user()->is_admin; return Auth::check() && $request->user()->is_admin;
}); });
Blade::directive('prettyNumber', function ($expression) {
$num = \App\Util\Lexer\PrettyNumber::convert($expression);
return "<?php echo $num; ?>";
});
Blade::directive('prettySize', function ($expression) {
$size = \App\Util\Lexer\PrettyNumber::size($expression);
return "<?php echo '$size'; ?>";
});
Blade::directive('maxFileSize', function () {
$value = config('pixelfed.max_photo_size');
return \App\Util\Lexer\PrettyNumber::size($value, true);
});
} }
/** /**

View file

@ -3,6 +3,7 @@
namespace App\Services; namespace App\Services;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use App\Like; use App\Like;
@ -10,42 +11,27 @@ class LikeService {
const CACHE_KEY = 'pf:services:likes:ids:'; const CACHE_KEY = 'pf:services:likes:ids:';
public static function getUser($profile_id) public static function add($profileId, $statusId)
{ {
return self::get($profile_id); $key = self::CACHE_KEY . $profileId . ':' . $statusId;
$ttl = now()->addHours(2);
return Cache::put($key, true, $ttl);
} }
protected static function get($profile_id) public static function remove($profileId, $statusId)
{ {
$key = self::CACHE_KEY . $profile_id; $key = self::CACHE_KEY . $profileId . ':' . $statusId;
if(Redis::zcard($key) == 0) { $ttl = now()->addHours(2);
self::warmCache($profile_id); return Cache::put($key, false, $ttl);
} else {
return Redis::zrevrange($key, 0, 40);
}
}
protected static function set($profile_id, $status_id)
{
$key = self::CACHE_KEY . $profile_id;
Redis::zadd($key, $status_id, $status_id);
}
public static function warmCache($profile_id)
{
Like::select('id', 'profile_id', 'status_id')
->whereProfileId($profile_id)
->latest()
->get()
->each(function($like) use ($profile_id) {
self::set($profile_id, $like->status_id);
});
} }
public static function liked($profileId, $statusId) public static function liked($profileId, $statusId)
{ {
$key = self::CACHE_KEY . $profileId; $key = self::CACHE_KEY . $profileId . ':' . $statusId;
return (bool) Redis::zrank($key, $statusId); $ttl = now()->addMinutes(30);
return Cache::remember($key, $ttl, function() use($profileId, $statusId) {
return Like::whereProfileId($profileId)->whereStatusId($statusId)->exists();
});
} }
public static function likedBy($status) public static function likedBy($status)

View file

@ -28,7 +28,8 @@ class PublicTimelineService {
public static function add($val) public static function add($val)
{ {
return Redis::zadd(self::CACHE_KEY, 1, $val); // return Redis::zadd(self::CACHE_KEY, $val, $val);
return;
} }
public static function rem($val) public static function rem($val)

BIN
public/js/timeline.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -709,7 +709,7 @@
recentFeed: this.scope === 'home' ? true : false, recentFeed: this.scope === 'home' ? true : false,
recentFeedMin: null, recentFeedMin: null,
recentFeedMax: null, recentFeedMax: null,
reactionBar: this.scope === 'network' ? false : true reactionBar: true
} }
}, },