Ver código fonte

Merge pull request #2998 from pixelfed/staging

Staging
daniel 3 anos atrás
pai
commit
71706d1e45
3 arquivos alterados com 16 adições e 5 exclusões
  1. 1 0
      CHANGELOG.md
  2. 9 3
      app/Services/AccountService.php
  3. 6 2
      app/Status.php

+ 1 - 0
CHANGELOG.md

@@ -26,6 +26,7 @@
 - Updated verify_credentials api endpoint to improve performance. ([7df3540b](https://github.com/pixelfed/pixelfed/commit/7df3540b))
 - Updated verify_credentials api endpoint to improve performance. ([7df3540b](https://github.com/pixelfed/pixelfed/commit/7df3540b))
 - Updated Localization util, filter out .DS_Store. ([0107e8fd](https://github.com/pixelfed/pixelfed/commit/0107e8fd))
 - Updated Localization util, filter out .DS_Store. ([0107e8fd](https://github.com/pixelfed/pixelfed/commit/0107e8fd))
 - Updated PublicApiController, fix private account statuses api. Closes #2995. ([aa2dd26c](https://github.com/pixelfed/pixelfed/commit/aa2dd26c))
 - Updated PublicApiController, fix private account statuses api. Closes #2995. ([aa2dd26c](https://github.com/pixelfed/pixelfed/commit/aa2dd26c))
+- Updated Status model, use AccountService to generate urls instead of loading profile relation. ([2ae527c0](https://github.com/pixelfed/pixelfed/commit/2ae527c0))
 -  ([](https://github.com/pixelfed/pixelfed/commit/))
 -  ([](https://github.com/pixelfed/pixelfed/commit/))
 
 
 ## [v0.11.1 (2021-09-07)](https://github.com/pixelfed/pixelfed/compare/v0.11.0...v0.11.1)
 ## [v0.11.1 (2021-09-07)](https://github.com/pixelfed/pixelfed/compare/v0.11.0...v0.11.1)

+ 9 - 3
app/Services/AccountService.php

@@ -15,7 +15,7 @@ class AccountService
 {
 {
 	const CACHE_KEY = 'pf:services:account:';
 	const CACHE_KEY = 'pf:services:account:';
 
 
-	public static function get($id)
+	public static function get($id, $softFail = false)
 	{
 	{
 		if($id > PHP_INT_MAX || $id < 1) {
 		if($id > PHP_INT_MAX || $id < 1) {
 			return [];
 			return [];
@@ -24,10 +24,16 @@ class AccountService
 		$key = self::CACHE_KEY . $id;
 		$key = self::CACHE_KEY . $id;
 		$ttl = now()->addHours(12);
 		$ttl = now()->addHours(12);
 
 
-		return Cache::remember($key, $ttl, function() use($id) {
+		return Cache::remember($key, $ttl, function() use($id, $softFail) {
 			$fractal = new Fractal\Manager();
 			$fractal = new Fractal\Manager();
 			$fractal->setSerializer(new ArraySerializer());
 			$fractal->setSerializer(new ArraySerializer());
-			$profile = Profile::findOrFail($id);
+			$profile = Profile::find($id);
+			if(!$profile) {
+				if($softFail) {
+					return null;
+				}
+				abort(404);
+			}
 			$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
 			$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
 			return $fractal->createData($resource)->toArray();
 			return $fractal->createData($resource)->toArray();
 		});	
 		});	

+ 6 - 2
app/Status.php

@@ -8,6 +8,7 @@ use App\HasSnowflakePrimary;
 use App\Http\Controllers\StatusController;
 use App\Http\Controllers\StatusController;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use App\Models\Poll;
 use App\Models\Poll;
+use App\Services\AccountService;
 
 
 class Status extends Model
 class Status extends Model
 {
 {
@@ -108,8 +109,11 @@ class Status extends Model
 			return $forceLocal ? "/i/web/post/_/{$this->profile_id}/{$this->id}" : $this->uri;
 			return $forceLocal ? "/i/web/post/_/{$this->profile_id}/{$this->id}" : $this->uri;
 		} else {
 		} else {
 			$id = $this->id;
 			$id = $this->id;
-			$username = $this->profile->username;
-			$path = url(config('app.url')."/p/{$username}/{$id}");
+			$account = AccountService::get($this->profile_id, true);
+			if(!$account || !isset($account['username'])) {
+				return '/404';
+			}
+			$path = url(config('app.url')."/p/{$account['username']}/{$id}");
 			return $path;
 			return $path;
 		}
 		}
 	}
 	}