1
0
Fork 0
forked from mirror/pixelfed

Update SiteController

This commit is contained in:
Daniel Supernault 2018-11-15 20:52:36 -07:00
parent 53e8da4837
commit 226d810159
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -33,12 +33,19 @@ class SiteController extends Controller
{ {
$pid = Auth::user()->profile->id; $pid = Auth::user()->profile->id;
// TODO: Use redis for timelines // TODO: Use redis for timelines
$following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id'); $following = Cache::rememberForever("user:following:list:$pid", function() use($pid) {
$following->push(Auth::user()->profile->id); $following = Follower::whereProfileId($pid)->pluck('following_id');
$filtered = UserFilter::whereUserId($pid) $following->push($pid);
return $following->toArray();
});
$filtered = Cache::rememberForever("user:filter:list:$pid", function() use($pid) {
return UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile') ->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block']) ->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id'); ->pluck('filterable_id')->toArray();
});
$timeline = Status::whereIn('profile_id', $following) $timeline = Status::whereIn('profile_id', $following)
->whereNotIn('profile_id', $filtered) ->whereNotIn('profile_id', $filtered)
->whereHas('media') ->whereHas('media')
@ -53,29 +60,22 @@ class SiteController extends Controller
public function changeLocale(Request $request, $locale) public function changeLocale(Request $request, $locale)
{ {
if (!App::isLocale($locale)) { // todo: add other locales after pushing new l10n strings
return redirect()->back(); $locales = ['en'];
if(in_array($locale, $locales)) {
session()->put('locale', $locale);
} }
App::setLocale($locale);
return redirect()->back(); return redirect()->back();
} }
public function about() public function about()
{ {
$res = Cache::remember('site:page:about', 15, function () { return view('site.about');
$statuses = Status::whereHas('media') }
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->count();
$statusCount = PrettyNumber::convert($statuses);
$userCount = PrettyNumber::convert(User::count());
$remoteCount = PrettyNumber::convert(Profile::whereNotNull('remote_url')->count());
$adminContact = User::whereIsAdmin(true)->first();
return view('site.about')->with(compact('statusCount', 'userCount', 'remoteCount', 'adminContact'))->render(); public function language()
}); {
return view('site.language');
return $res;
} }
} }