mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 08:13:16 +00:00
Update Cache, prepare for laravel 5.8
This commit is contained in:
parent
6bbef6ac4e
commit
4739c25fe0
15 changed files with 31 additions and 30 deletions
|
@ -36,16 +36,16 @@ trait AdminSettingsController
|
||||||
|
|
||||||
public function settingsStorage(Request $request)
|
public function settingsStorage(Request $request)
|
||||||
{
|
{
|
||||||
$databaseSum = Cache::remember('admin:settings:storage:db:storageUsed', 360, function() {
|
$databaseSum = Cache::remember('admin:settings:storage:db:storageUsed', now()->addMinutes(360), function() {
|
||||||
$q = 'SELECT sum(ROUND(((data_length + index_length)), 0)) AS size FROM information_schema.TABLES WHERE table_schema = ?';
|
$q = 'SELECT sum(ROUND(((data_length + index_length)), 0)) AS size FROM information_schema.TABLES WHERE table_schema = ?';
|
||||||
$db = config('database.default');
|
$db = config('database.default');
|
||||||
$db = config("database.connections.{$db}.database");
|
$db = config("database.connections.{$db}.database");
|
||||||
return DB::select($q, [$db])[0]->size;
|
return DB::select($q, [$db])[0]->size;
|
||||||
});
|
});
|
||||||
$mediaSum = Cache::remember('admin:settings:storage:media:storageUsed', 360, function() {
|
$mediaSum = Cache::remember('admin:settings:storage:media:storageUsed', now()->addMinutes(360), function() {
|
||||||
return Media::sum('size');
|
return Media::sum('size');
|
||||||
});
|
});
|
||||||
$backupSum = Cache::remember('admin:settings:storage:backups:storageUsed', 360, function() {
|
$backupSum = Cache::remember('admin:settings:storage:backups:storageUsed', now()->addMinutes(360), function() {
|
||||||
$dir = storage_path('app/'.config('app.name'));
|
$dir = storage_path('app/'.config('app.name'));
|
||||||
$size = 0;
|
$size = 0;
|
||||||
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
|
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ class AdminController extends Controller
|
||||||
|
|
||||||
public function home()
|
public function home()
|
||||||
{
|
{
|
||||||
$data = Cache::remember('admin:dashboard:home:data', 15, function() {
|
$data = Cache::remember('admin:dashboard:home:data', now()->addMinutes(15), function() {
|
||||||
$day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day(';
|
$day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day(';
|
||||||
return [
|
return [
|
||||||
'failedjobs' => [
|
'failedjobs' => [
|
||||||
|
|
|
@ -57,7 +57,7 @@ class BaseApiController extends Controller
|
||||||
{
|
{
|
||||||
$pid = Auth::user()->profile->id;
|
$pid = Auth::user()->profile->id;
|
||||||
$page = $request->input('page') ?? 1;
|
$page = $request->input('page') ?? 1;
|
||||||
$res = Cache::remember('profile:notifications:'.$pid.':page:'.$page, 5, function() use($pid) {
|
$res = Cache::remember('profile:notifications:'.$pid.':page:'.$page, now()->addMinutes(5), function() use($pid) {
|
||||||
$timeago = Carbon::now()->subMonths(6);
|
$timeago = Carbon::now()->subMonths(6);
|
||||||
$notifications = Notification::whereHas('actor')
|
$notifications = Notification::whereHas('actor')
|
||||||
->whereProfileId($pid)
|
->whereProfileId($pid)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class InstanceApiController extends Controller {
|
||||||
|
|
||||||
protected function getData()
|
protected function getData()
|
||||||
{
|
{
|
||||||
$contact = Cache::remember('api:v1:instance:contact', 1440, function() {
|
$contact = Cache::remember('api:v1:instance:contact', now()->addMinutes(1440), function() {
|
||||||
$admin = User::whereIsAdmin(true)->first()->profile;
|
$admin = User::whereIsAdmin(true)->first()->profile;
|
||||||
return [
|
return [
|
||||||
'id' => $admin->id,
|
'id' => $admin->id,
|
||||||
|
@ -56,7 +56,7 @@ class InstanceApiController extends Controller {
|
||||||
|
|
||||||
public function instance()
|
public function instance()
|
||||||
{
|
{
|
||||||
$res = Cache::remember('api:v1:instance', 60, function() {
|
$res = Cache::remember('api:v1:instance', now()->addMinutes(60), function() {
|
||||||
return json_encode($this->getData());
|
return json_encode($this->getData());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Illuminate\Http\Request;
|
||||||
|
|
||||||
class ApiController extends BaseApiController
|
class ApiController extends BaseApiController
|
||||||
{
|
{
|
||||||
|
// todo: deprecate and remove
|
||||||
public function hydrateLikes(Request $request)
|
public function hydrateLikes(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
@ -18,7 +19,7 @@ class ApiController extends BaseApiController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
$res = Cache::remember('api:like-ids:user:'.$profile->id, 1440, function () use ($profile) {
|
$res = Cache::remember('api:like-ids:user:'.$profile->id, now()->addDays(1), function () use ($profile) {
|
||||||
return Like::whereProfileId($profile->id)
|
return Like::whereProfileId($profile->id)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->take(1000)
|
->take(1000)
|
||||||
|
|
|
@ -80,7 +80,7 @@ class FederationController extends Controller
|
||||||
|
|
||||||
public function nodeinfo()
|
public function nodeinfo()
|
||||||
{
|
{
|
||||||
$res = Cache::remember('api:nodeinfo', 60, function () {
|
$res = Cache::remember('api:nodeinfo', now()->addHours(1), function () {
|
||||||
return [
|
return [
|
||||||
'metadata' => [
|
'metadata' => [
|
||||||
'nodeName' => config('app.name'),
|
'nodeName' => config('app.name'),
|
||||||
|
|
|
@ -105,10 +105,10 @@ class InternalApiController extends Controller
|
||||||
{
|
{
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
$pid = $profile->id;
|
$pid = $profile->id;
|
||||||
$following = Cache::remember('feature:discover:following:'.$pid, 60, function() use ($pid) {
|
$following = Cache::remember('feature:discover:following:'.$pid, now()->addMinutes(60), function() use ($pid) {
|
||||||
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
||||||
});
|
});
|
||||||
$filters = Cache::remember("user:filter:list:$pid", 60, function() use($pid) {
|
$filters = Cache::remember("user:filter:list:$pid", now()->addMinutes(60), function() use($pid) {
|
||||||
return UserFilter::whereUserId($pid)
|
return UserFilter::whereUserId($pid)
|
||||||
->whereFilterableType('App\Profile')
|
->whereFilterableType('App\Profile')
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
|
@ -161,10 +161,10 @@ class InternalApiController extends Controller
|
||||||
{
|
{
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
$pid = $profile->id;
|
$pid = $profile->id;
|
||||||
$following = Cache::remember('feature:discover:following:'.$pid, 60, function() use ($pid) {
|
$following = Cache::remember('feature:discover:following:'.$pid, now()->addMinutes(60), function() use ($pid) {
|
||||||
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
||||||
});
|
});
|
||||||
$filters = Cache::remember("user:filter:list:$pid", 60, function() use($pid) {
|
$filters = Cache::remember("user:filter:list:$pid", now()->addMinutes(60), function() use($pid) {
|
||||||
return UserFilter::whereUserId($pid)
|
return UserFilter::whereUserId($pid)
|
||||||
->whereFilterableType('App\Profile')
|
->whereFilterableType('App\Profile')
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
|
@ -200,10 +200,10 @@ class InternalApiController extends Controller
|
||||||
{
|
{
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
$pid = $profile->id;
|
$pid = $profile->id;
|
||||||
$following = Cache::remember('feature:discover:following:'.$pid, 15, function() use ($pid) {
|
$following = Cache::remember('feature:discover:following:'.$pid, now()->addMinutes(15), function() use ($pid) {
|
||||||
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
||||||
});
|
});
|
||||||
$filters = Cache::remember("user:filter:list:$pid", 15, function() use($pid) {
|
$filters = Cache::remember("user:filter:list:$pid", now()->addMinutes(15), function() use($pid) {
|
||||||
$private = Profile::whereIsPrivate(true)
|
$private = Profile::whereIsPrivate(true)
|
||||||
->orWhere('unlisted', true)
|
->orWhere('unlisted', true)
|
||||||
->orWhere('status', '!=', null)
|
->orWhere('status', '!=', null)
|
||||||
|
|
|
@ -48,7 +48,7 @@ class LikeController extends Controller
|
||||||
->take(1000)
|
->take(1000)
|
||||||
->pluck('status_id');
|
->pluck('status_id');
|
||||||
|
|
||||||
Cache::put('api:like-ids:user:'.$profile->id, $likes, 1440);
|
Cache::put('api:like-ids:user:'.$profile->id, $likes, now()->addMinutes(1440));
|
||||||
|
|
||||||
if ($request->ajax()) {
|
if ($request->ajax()) {
|
||||||
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
|
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
|
||||||
|
|
|
@ -223,7 +223,7 @@ class PublicApiController extends Controller
|
||||||
// $timeline = Timeline::build()->local();
|
// $timeline = Timeline::build()->local();
|
||||||
$pid = Auth::user()->profile->id;
|
$pid = Auth::user()->profile->id;
|
||||||
|
|
||||||
$private = Cache::remember('profiles:private', 1440, function() {
|
$private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
|
||||||
return Profile::whereIsPrivate(true)
|
return Profile::whereIsPrivate(true)
|
||||||
->orWhere('unlisted', true)
|
->orWhere('unlisted', true)
|
||||||
->orWhere('status', '!=', null)
|
->orWhere('status', '!=', null)
|
||||||
|
@ -317,7 +317,7 @@ class PublicApiController extends Controller
|
||||||
// $timeline = Timeline::build()->local();
|
// $timeline = Timeline::build()->local();
|
||||||
$pid = Auth::user()->profile->id;
|
$pid = Auth::user()->profile->id;
|
||||||
|
|
||||||
$following = Cache::remember('profile:following:'.$pid, 1440, function() use($pid) {
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
||||||
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
||||||
return $following->push($pid)->toArray();
|
return $following->push($pid)->toArray();
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ class SearchController extends Controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$hash = hash('sha256', $tag);
|
$hash = hash('sha256', $tag);
|
||||||
$tokens = Cache::remember('api:search:tag:'.$hash, 5, function () use ($tag) {
|
$tokens = Cache::remember('api:search:tag:'.$hash, now()->addMinutes(5), function () use ($tag) {
|
||||||
$tokens = collect([]);
|
$tokens = collect([]);
|
||||||
if(Helpers::validateUrl($tag)) {
|
if(Helpers::validateUrl($tag)) {
|
||||||
$remote = Helpers::fetchFromUrl($tag);
|
$remote = Helpers::fetchFromUrl($tag);
|
||||||
|
@ -85,6 +85,7 @@ class SearchController extends Controller
|
||||||
'value' => $item->username,
|
'value' => $item->username,
|
||||||
'tokens' => [$item->username],
|
'tokens' => [$item->username],
|
||||||
'name' => $item->name,
|
'name' => $item->name,
|
||||||
|
'id' => $item->id
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
$tokens->push($profiles);
|
$tokens->push($profiles);
|
||||||
|
|
|
@ -74,7 +74,7 @@ class SettingsController extends Controller
|
||||||
|
|
||||||
public function exportFollowing()
|
public function exportFollowing()
|
||||||
{
|
{
|
||||||
$data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, 1440, function() {
|
$data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, now()->addMinutes(1440), function() {
|
||||||
return Auth::user()->profile->following()->get()->map(function($i) {
|
return Auth::user()->profile->following()->get()->map(function($i) {
|
||||||
return $i->url();
|
return $i->url();
|
||||||
});
|
});
|
||||||
|
@ -86,7 +86,7 @@ class SettingsController extends Controller
|
||||||
|
|
||||||
public function exportFollowers()
|
public function exportFollowers()
|
||||||
{
|
{
|
||||||
$data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, 1440, function() {
|
$data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, now()->addMinutes(1440), function() {
|
||||||
return Auth::user()->profile->followers()->get()->map(function($i) {
|
return Auth::user()->profile->followers()->get()->map(function($i) {
|
||||||
return $i->url();
|
return $i->url();
|
||||||
});
|
});
|
||||||
|
@ -105,7 +105,7 @@ class SettingsController extends Controller
|
||||||
if(!$exists) {
|
if(!$exists) {
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
$data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, 1440, function() use($profile) {
|
$data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, now()->addMinutes(1440), function() use($profile) {
|
||||||
return json_encode([
|
return json_encode([
|
||||||
'muted' => $profile->mutedProfileUrls(),
|
'muted' => $profile->mutedProfileUrls(),
|
||||||
'blocked' => $profile->blockedProfileUrls()
|
'blocked' => $profile->blockedProfileUrls()
|
||||||
|
|
|
@ -41,10 +41,10 @@ class SiteController extends Controller
|
||||||
|
|
||||||
public function about()
|
public function about()
|
||||||
{
|
{
|
||||||
$res = Cache::remember('site:about', 120, function() {
|
$res = Cache::remember('site:about', now()->addMinutes(120), function() {
|
||||||
$custom = Page::whereSlug('/site/about')->whereActive(true)->exists();
|
$custom = Page::whereSlug('/site/about')->whereActive(true)->exists();
|
||||||
if($custom) {
|
if($custom) {
|
||||||
$stats = Cache::remember('site:about:stats', 60, function() {
|
$stats = Cache::remember('site:about:stats', now()->addMinutes(60), function() {
|
||||||
return [
|
return [
|
||||||
'posts' => Status::whereLocal(true)->count(),
|
'posts' => Status::whereLocal(true)->count(),
|
||||||
'users' => User::count(),
|
'users' => User::count(),
|
||||||
|
@ -53,7 +53,7 @@ class SiteController extends Controller
|
||||||
});
|
});
|
||||||
return View::make('site.about')->with('stats', $stats)->render();
|
return View::make('site.about')->with('stats', $stats)->render();
|
||||||
} else {
|
} else {
|
||||||
$stats = Cache::remember('site:about:stats', 60, function() {
|
$stats = Cache::remember('site:about:stats', now()->addMinutes(60), function() {
|
||||||
return [
|
return [
|
||||||
'posts' => Status::whereLocal(true)->count(),
|
'posts' => Status::whereLocal(true)->count(),
|
||||||
'users' => User::count(),
|
'users' => User::count(),
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Profile extends Model
|
||||||
|
|
||||||
public function avatarUrl()
|
public function avatarUrl()
|
||||||
{
|
{
|
||||||
$url = Cache::remember("avatar:{$this->id}", 1440, function () {
|
$url = Cache::remember("avatar:{$this->id}", now()->addDays(1), function () {
|
||||||
$path = optional($this->avatar)->media_path;
|
$path = optional($this->avatar)->media_path;
|
||||||
$version = hash('sha1', $this->avatar->updated_at);
|
$version = hash('sha1', $this->avatar->updated_at);
|
||||||
$path = "{$path}?v={$version}";
|
$path = "{$path}?v={$version}";
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Auth, Cache;
|
use Auth, Cache, Hashids, Storage;
|
||||||
use App\Http\Controllers\StatusController;
|
use App\Http\Controllers\StatusController;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Storage;
|
|
||||||
|
|
||||||
class Status extends Model
|
class Status extends Model
|
||||||
{
|
{
|
||||||
|
@ -77,7 +76,7 @@ class Status extends Model
|
||||||
|
|
||||||
public function thumb($showNsfw = false)
|
public function thumb($showNsfw = false)
|
||||||
{
|
{
|
||||||
return Cache::remember('status:thumb:'.$this->id, 40320, function() use ($showNsfw) {
|
return Cache::remember('status:thumb:'.$this->id, now()->addMinutes(15), function() use ($showNsfw) {
|
||||||
$type = $this->type ?? $this->setType();
|
$type = $this->type ?? $this->setType();
|
||||||
$is_nsfw = !$showNsfw ? $this->is_nsfw : false;
|
$is_nsfw = !$showNsfw ? $this->is_nsfw : false;
|
||||||
if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['photo', 'photo:album'])) {
|
if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['photo', 'photo:album'])) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
|
|
||||||
public function includeMediaAttachments(Status $status)
|
public function includeMediaAttachments(Status $status)
|
||||||
{
|
{
|
||||||
return Cache::remember('status:transformer:media:attachments:'.$status->id, 1440, function() use($status) {
|
return Cache::remember('status:transformer:media:attachments:'.$status->id, now()->addMinutes(1440), function() use($status) {
|
||||||
$media = $status->media()->orderBy('order')->get();
|
$media = $status->media()->orderBy('order')->get();
|
||||||
return $this->collection($media, new MediaTransformer());
|
return $this->collection($media, new MediaTransformer());
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue