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 144 additions and 103 deletions

View File

@ -38,6 +38,7 @@
- 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 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/))
## [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\{
AccountService,
LikeService,
PublicTimelineService,
StatusService,
SnowflakeService,
@ -527,8 +528,10 @@ class PublicApiController extends Controller
->orderBy('created_at', 'desc')
->limit($limit)
->get()
->map(function($s) {
return StatusService::get($s->id);
->map(function($s) use ($user) {
$status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status;
});
$res = $timeline->toArray();
} else {
@ -543,11 +546,13 @@ class PublicApiController extends Controller
->whereScope('public')
->where('id', '>', $amin)
->orderBy('created_at', 'desc')
->limit($limit)
->get()
->map(function($s) {
return StatusService::get($s->id);
});
->limit($limit)
->get()
->map(function($s) use ($user) {
$status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status;
});
$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

@ -3,22 +3,24 @@
namespace App\Providers;
use App\Observers\{
AvatarObserver,
NotificationObserver,
ModLogObserver,
ProfileObserver,
StatusHashtagObserver,
UserObserver,
UserFilterObserver,
AvatarObserver,
LikeObserver,
NotificationObserver,
ModLogObserver,
ProfileObserver,
StatusHashtagObserver,
UserObserver,
UserFilterObserver,
};
use App\{
Avatar,
Notification,
ModLog,
Profile,
StatusHashtag,
User,
UserFilter
Avatar,
Like,
Notification,
ModLog,
Profile,
StatusHashtag,
User,
UserFilter
};
use Auth, Horizon, URL;
use Illuminate\Support\Facades\Blade;
@ -28,54 +30,36 @@ use Illuminate\Pagination\Paginator;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
URL::forceScheme('https');
Schema::defaultStringLength(191);
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
URL::forceScheme('https');
Schema::defaultStringLength(191);
Paginator::useBootstrap();
Avatar::observe(AvatarObserver::class);
Like::observe(LikeObserver::class);
Notification::observe(NotificationObserver::class);
ModLog::observe(ModLogObserver::class);
Profile::observe(ProfileObserver::class);
StatusHashtag::observe(StatusHashtagObserver::class);
User::observe(UserObserver::class);
UserFilter::observe(UserFilterObserver::class);
Horizon::auth(function ($request) {
return Auth::check() && $request->user()->is_admin;
});
}
Paginator::useBootstrap();
Avatar::observe(AvatarObserver::class);
Notification::observe(NotificationObserver::class);
ModLog::observe(ModLogObserver::class);
Profile::observe(ProfileObserver::class);
StatusHashtag::observe(StatusHashtagObserver::class);
User::observe(UserObserver::class);
UserFilter::observe(UserFilterObserver::class);
Horizon::auth(function ($request) {
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);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

View File

@ -3,6 +3,7 @@
namespace App\Services;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use App\Like;
@ -10,42 +11,27 @@ class LikeService {
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;
if(Redis::zcard($key) == 0) {
self::warmCache($profile_id);
} 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);
});
$key = self::CACHE_KEY . $profileId . ':' . $statusId;
$ttl = now()->addHours(2);
return Cache::put($key, false, $ttl);
}
public static function liked($profileId, $statusId)
{
$key = self::CACHE_KEY . $profileId;
return (bool) Redis::zrank($key, $statusId);
$key = self::CACHE_KEY . $profileId . ':' . $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)

View File

@ -28,7 +28,8 @@ class PublicTimelineService {
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)
@ -64,4 +65,4 @@ class PublicTimelineService {
}
return 0;
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -30,5 +30,5 @@
"/js/status.js": "/js/status.js?id=bde5811432c2db213f0d",
"/js/story-compose.js": "/js/story-compose.js?id=b16bcf2adad9651735e1",
"/js/theme-monokai.js": "/js/theme-monokai.js?id=8842103833ba4861bcfa",
"/js/timeline.js": "/js/timeline.js?id=8f2f7924e8b7eefd656f"
"/js/timeline.js": "/js/timeline.js?id=90a61b8bf6241d29f9cb"
}

View File

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