Merge pull request #1356 from pixelfed/frontend-ui-refactor

Update NotificationService
This commit is contained in:
daniel 2019-06-05 01:19:00 -06:00 committed by GitHub
commit d37a3617d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View file

@ -119,14 +119,16 @@ class Profile extends Model
{ {
return $this->hasOne(Avatar::class)->withDefault([ return $this->hasOne(Avatar::class)->withDefault([
'media_path' => 'public/avatars/default.png', 'media_path' => 'public/avatars/default.png',
'change_count' => 0
]); ]);
} }
public function avatarUrl() public function avatarUrl()
{ {
$url = Cache::remember("avatar:{$this->id}", now()->addDays(1), function () { $url = Cache::remember("avatar:{$this->id}", now()->addYears(1), function () {
$path = optional($this->avatar)->media_path; $avatar = $this->avatar;
$version = hash('sha1', $this->avatar->updated_at); $path = $avatar->media_path;
$version = hash('sha256', $avatar->change_count);
$path = "{$path}?v={$version}"; $path = "{$path}?v={$version}";
return url(Storage::url($path)); return url(Storage::url($path));

View file

@ -16,11 +16,11 @@ class NotificationService {
const CACHE_KEY = 'pf:services:notifications:ids:'; const CACHE_KEY = 'pf:services:notifications:ids:';
public static function get($id, $start = 0, $stop = 300) public static function get($id, $start = 0, $stop = 400)
{ {
$res = collect([]); $res = collect([]);
$key = self::CACHE_KEY . $id; $key = self::CACHE_KEY . $id;
$stop = $stop > 300 ? 300 : $stop; $stop = $stop > 400 ? 400 : $stop;
$ids = Redis::zrangebyscore($key, $start, $stop); $ids = Redis::zrangebyscore($key, $start, $stop);
if(empty($ids)) { if(empty($ids)) {
$ids = self::coldGet($id, $start, $stop); $ids = self::coldGet($id, $start, $stop);
@ -31,9 +31,9 @@ class NotificationService {
return $res; return $res;
} }
public static function coldGet($id, $start = 0, $stop = 300) public static function coldGet($id, $start = 0, $stop = 400)
{ {
$stop = $stop > 300 ? 300 : $stop; $stop = $stop > 400 ? 400 : $stop;
$ids = Notification::whereProfileId($id) $ids = Notification::whereProfileId($id)
->latest() ->latest()
->skip($start) ->skip($start)
@ -72,7 +72,7 @@ class NotificationService {
public static function getNotification($id) public static function getNotification($id)
{ {
return Cache::remember('service:notification:'.$id, now()->addDays(7), function() use($id) { return Cache::remember('service:notification:'.$id, now()->addMonths(3), function() use($id) {
$n = Notification::with('item')->findOrFail($id); $n = Notification::with('item')->findOrFail($id);
$fractal = new Fractal\Manager(); $fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer()); $fractal->setSerializer(new ArraySerializer());
@ -83,7 +83,7 @@ class NotificationService {
public static function setNotification(Notification $notification) public static function setNotification(Notification $notification)
{ {
return Cache::remember('service:notification:'.$notification->id, now()->addDays(7), function() use($notification) { return Cache::remember('service:notification:'.$notification->id, now()->addMonths(3), function() use($notification) {
$fractal = new Fractal\Manager(); $fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer()); $fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($notification, new NotificationTransformer()); $resource = new Fractal\Resource\Item($notification, new NotificationTransformer());
@ -91,7 +91,7 @@ class NotificationService {
}); });
} }
public static function warmCache($id, $stop = 100, $force = false) public static function warmCache($id, $stop = 400, $force = false)
{ {
if(self::count($id) == 0 || $force == true) { if(self::count($id) == 0 || $force == true) {
$ids = Notification::whereProfileId($id) $ids = Notification::whereProfileId($id)

View file

@ -16,7 +16,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
'acct' => $profile->username, 'acct' => $profile->username,
'display_name' => $profile->name, 'display_name' => $profile->name,
'locked' => (bool) $profile->is_private, 'locked' => (bool) $profile->is_private,
'created_at' => $profile->created_at->format('c'), 'created_at' => null,
'followers_count' => $profile->followerCount(), 'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(), 'following_count' => $profile->followingCount(),
'statuses_count' => $profile->statusCount(), 'statuses_count' => $profile->statusCount(),