1
0
Fork 0

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([
'media_path' => 'public/avatars/default.png',
'change_count' => 0
]);
}
public function avatarUrl()
{
$url = Cache::remember("avatar:{$this->id}", now()->addDays(1), function () {
$path = optional($this->avatar)->media_path;
$version = hash('sha1', $this->avatar->updated_at);
$url = Cache::remember("avatar:{$this->id}", now()->addYears(1), function () {
$avatar = $this->avatar;
$path = $avatar->media_path;
$version = hash('sha256', $avatar->change_count);
$path = "{$path}?v={$version}";
return url(Storage::url($path));

View File

@ -16,11 +16,11 @@ class NotificationService {
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([]);
$key = self::CACHE_KEY . $id;
$stop = $stop > 300 ? 300 : $stop;
$stop = $stop > 400 ? 400 : $stop;
$ids = Redis::zrangebyscore($key, $start, $stop);
if(empty($ids)) {
$ids = self::coldGet($id, $start, $stop);
@ -31,9 +31,9 @@ class NotificationService {
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)
->latest()
->skip($start)
@ -72,7 +72,7 @@ class NotificationService {
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);
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
@ -83,7 +83,7 @@ class NotificationService {
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->setSerializer(new ArraySerializer());
$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) {
$ids = Notification::whereProfileId($id)

View File

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