浏览代码

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

Update NotificationService
daniel 6 年之前
父节点
当前提交
d37a3617d5
共有 3 个文件被更改,包括 13 次插入11 次删除
  1. 5 3
      app/Profile.php
  2. 7 7
      app/Services/NotificationService.php
  3. 1 1
      app/Transformer/Api/AccountTransformer.php

+ 5 - 3
app/Profile.php

@@ -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));

+ 7 - 7
app/Services/NotificationService.php

@@ -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)

+ 1 - 1
app/Transformer/Api/AccountTransformer.php

@@ -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(),