Merge pull request #2603 from pixelfed/staging

Staging
This commit is contained in:
daniel 2021-01-31 01:01:41 -07:00 committed by GitHub
commit 59edf497bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 303 deletions

View file

@ -23,6 +23,7 @@
- Updated AP helpers, fix statusFetch 404s. ([3419379a](https://github.com/pixelfed/pixelfed/commit/3419379a))
- Updated InternalApiController, update discoverPosts method to improve performance. ([9862a855](https://github.com/pixelfed/pixelfed/commit/9862a855))
- Updated DiscoverComponent, add blurhash and like/comment counts. ([a8ebdd2e](https://github.com/pixelfed/pixelfed/commit/a8ebdd2e))
- Updated DiscoverComponent, add spinner loaders and remove deprecated sections. ([34869247](https://github.com/pixelfed/pixelfed/commit/34869247))
- ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)

View file

@ -54,63 +54,21 @@ class DiscoverController extends Controller
public function showCategory(Request $request, $slug)
{
abort_if(!Auth::check(), 403);
$tag = DiscoverCategory::whereActive(true)
->whereSlug($slug)
->firstOrFail();
$posts = Cache::remember('discover:category-'.$tag->id.':posts', now()->addMinutes(15), function() use ($tag) {
$tagids = $tag->hashtags->pluck('id')->toArray();
$sids = StatusHashtag::whereIn('hashtag_id', $tagids)->orderByDesc('status_id')->take(500)->pluck('status_id')->toArray();
$posts = Status::whereScope('public')->whereIn('id', $sids)->whereNull('uri')->whereType('photo')->whereNull('in_reply_to_id')->whereNull('reblog_of_id')->orderByDesc('created_at')->take(39)->get();
return $posts;
});
$tag->posts_count = Cache::remember('discover:category-'.$tag->id.':posts_count', now()->addMinutes(30), function() use ($tag) {
return $tag->posts()->whereScope('public')->count();
});
return view('discover.tags.category', compact('tag', 'posts'));
abort(404);
}
public function showLoops(Request $request)
{
if(config('exp.loops') != true) {
return redirect('/');
}
return view('discover.loops.home');
abort(404);
}
public function loopsApi(Request $request)
{
abort_if(!config('exp.loops'), 403);
// todo proper pagination, maybe LoopService
$res = Cache::remember('discover:loops:recent', now()->addHours(6), function() {
$loops = Status::whereType('video')
->whereNull('uri')
->whereScope('public')
->latest()
->take(18)
->get();
$resource = new Fractal\Resource\Collection($loops, new StatusStatelessTransformer());
return $this->fractal->createData($resource)->toArray();
});
return $res;
abort(404);
}
public function loopWatch(Request $request)
{
abort_if(!Auth::check(), 403);
abort_if(!config('exp.loops'), 403);
$this->validate($request, [
'id' => 'integer|min:1'
]);
$id = $request->input('id');
// todo log loops
return response()->json(200);
}
@ -144,35 +102,13 @@ class DiscoverController extends Controller
public function profilesDirectory(Request $request)
{
return redirect('/')->with('statusRedirect', 'The Profile Directory is unavailable at this time.');
return view('discover.profiles.home');
return redirect('/')
->with('statusRedirect', 'The Profile Directory is unavailable at this time.');
}
public function profilesDirectoryApi(Request $request)
{
return ['error' => 'Temporarily unavailable.'];
$this->validate($request, [
'page' => 'integer|max:10'
]);
$page = $request->input('page') ?? 1;
$key = 'discover:profiles:page:' . $page;
$ttl = now()->addHours(12);
$res = Cache::remember($key, $ttl, function() {
$profiles = Profile::whereNull('domain')
->whereNull('status')
->whereIsPrivate(false)
->has('statuses')
->whereIsSuggestable(true)
// ->inRandomOrder()
->simplePaginate(8);
$resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
return $this->fractal->createData($resource)->toArray();
});
return $res;
}
public function trendingApi(Request $request)
@ -221,45 +157,10 @@ class DiscoverController extends Controller
public function trendingHashtags(Request $request)
{
return [];
$res = StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
->groupBy('hashtag_id')
->orderBy('total','desc')
->where('created_at', '>', now()->subDays(4))
->take(9)
->get()
->map(function($h) {
$hashtag = $h->hashtag;
return [
'id' => $hashtag->id,
'total' => $h->total,
'name' => '#'.$hashtag->name,
'url' => $hashtag->url('?src=dsh1')
];
});
return $res;
}
public function trendingPlaces(Request $request)
{
return [];
$res = Status::select('place_id',DB::raw('count(place_id) as total'))
->whereNotNull('place_id')
->where('created_at','>',now()->subDays(14))
->groupBy('place_id')
->orderBy('total')
->limit(4)
->get()
->map(function($s){
$p = $s->place;
return [
'name' => $p->name,
'country' => $p->country,
'url' => $p->url()
];
});
return [];
}
}

View file

@ -64,7 +64,7 @@ class StatusHashtagService {
$key = 'pf:services:status-hashtag:count:' . $id;
$ttl = now()->addMinutes(5);
return Cache::remember($key, $ttl, function() use($id) {
return StatusHashtag::whereHashtagId($id)->count();
return StatusHashtag::whereHashtagId($id)->has('media')->count();
});
}

BIN
public/js/discover.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -7,24 +7,8 @@
<div class="d-block d-md-none border-top-0 pt-3">
<input class="form-control rounded-pill shadow-sm" placeholder="Search" v-model="searchTerm" v-on:keyup.enter="searchSubmit">
</div>
<div class="pt-3">
<p class="d-block d-md-none h1 font-weight-bold text-lighter pt-3" style="opacity: 0.4"><i class="far fa-compass"></i> DISCOVER</p>
<p class="d-none d-md-block display-3 font-weight-bold text-lighter pt-3" style="opacity: 0.4"><i class="far fa-compass"></i> DISCOVER</p>
</div>
<section v-if="hashtags.length" class="mb-4 pb-5 section-explore mt-4 pt-4">
<div class="lead">
<i class="fas fa-hashtag text-lighter fa-lg mr-3"></i>
<a v-for="(tag, index) in hashtags" :href="tag.url" class="badge badge-light rounded-pill border py-2 px-3 mr-2 mb-2 shadow-sm border-danger text-danger">{{tag.name}}</a>
</div>
<div class="lead mt-4">
<i class="fas fa-map-marker-alt text-lighter fa-lg mr-3"></i>
<a v-for="(tag, index) in places" :href="tag.url" class="badge badge-light rounded-pill border py-2 px-3 mr-2 mb-2 shadow-sm border-danger text-danger">{{tag.name}}, {{tag.country}}</a>
</div>
</section>
<section v-if="trending.length" class="mb-5 section-explore">
<section class="mt-3 mb-5 section-explore">
<div class="profile-timeline">
<div class="row p-0 mt-5">
<div class="col-12 mb-3 d-flex justify-content-between align-items-center">
@ -38,8 +22,8 @@
</div>
</div>
</div>
<div class="row p-0" style="display: flex;">
<div v-for="(s, index) in trending.slice(0, 12)" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
<div v-if="!trendingLoading" class="row p-0 d-flex">
<div v-if="trending.length" v-for="(s, index) in trending.slice(0, 12)" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
<a class="card info-overlay card-md-border-0" :href="s.url">
<div class="square">
<div v-if="s.sensitive" class="square-content">
@ -83,83 +67,28 @@
</div>
</a>
</div>
<div v-else class="col-12 d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
<div class="h2">No posts found :(</div>
</div>
</div>
<div v-else class="row d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</section>
<section v-if="categories.length > 0" class="mb-5 section-explore">
<section class="pt-5 mb-5 section-explore">
<div class="profile-timeline pt-3">
<div class="row p-0 mt-5">
<div class="col-12 mb-4 d-flex justify-content-between align-items-center">
<p class="d-block d-md-none h1 font-weight-bold mb-0">Categories</p>
<p class="d-none d-md-block display-4 font-weight-bold mb-0">Categories</p>
</div>
</div>
<section class="d-none d-md-flex mb-md-2 discover-bar" style="width:auto; overflow: auto hidden;">
<a v-for="(category, index) in categories" :key="index+'_cat_'" class="bg-dark rounded d-inline-flex align-items-end justify-content-center mr-3 box-shadow card-disc text-decoration-none" :href="category.url" :style="'background: linear-gradient(rgba(0, 0, 0, 0.3),rgba(0, 0, 0, 0.3)),url('+category.thumb+');'">
<p class="text-white font-weight-bold" style="text-shadow: 3px 3px 16px #272634;">{{category.name}}</p>
</a>
</section>
</div>
</section>
<section v-if="categories.length > 0" class="py-5 mb-5 section-explore bg-warning rounded">
<div class="profile-timeline py-3">
<div class="row p-0 my-5">
<div class="col-12 mb-3 text-center text-dark">
<p class="d-none d-md-block display-3 font-weight-bold">Discover. Categories.</p>
<p class="d-block d-md-none h1 font-weight-bold">Discover. Categories.</p>
<p class="h4 font-weight-light mb-0">Discover amazing posts, people, places and hashtags.</p>
</div>
</div>
</div>
</section>
<section v-if="posts.length" class="pt-5 mb-5 section-explore">
<div class="profile-timeline pt-3">
<div class="row p-0 mt-5">
<!-- <div class="col-12 mb-3 d-flex justify-content-between align-items-center">
<p class="d-block d-md-none h1 font-weight-bold mb-0">Spotlight</p>
<p class="d-none d-md-block display-4 font-weight-bold mb-0">Spotlight</p>
<div>
<div class="btn-group">
<button class="btn btn-danger py-1 font-weight-bold px-3 text-uppercase btn-sm">Today</button>
<button class="btn btn-outline-danger py-1 font-weight-bold px-3 text-uppercase btn-sm">Yesterday</button>
</div>
</div>
</div> -->
<!-- <div class="col-12 col-md-6">
<div class="mb-4">
<a class="card info-overlay card-md-border-0" :href="posts[10].url">
<div class="square">
<span v-if="posts[10].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
<span v-if="posts[10].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
<span v-if="posts[10].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
<div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[10].thumb + ')' }">
</div>
</div>
</a>
</div>
</div>
<div class="col-12 col-md-6 row p-0 m-0">
<div v-for="(post, index) in posts.slice(11,15)" class="col-6" style="margin-bottom:1.8rem;">
<a class="card info-overlay card-md-border-0" :href="post.url">
<div class="square">
<span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
<span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
<span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
<div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
</div>
</div>
</a>
</div>
</div> -->
<div class="col-12 mb-3 d-flex justify-content-between align-items-center">
<p class="d-block d-md-none h1 font-weight-bold mb-0">For You</p>
<p class="d-none d-md-block display-4 font-weight-bold mb-0">For You</p>
</div>
</div>
<div class="row p-0" style="display: flex;">
<div v-for="(s, index) in posts" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
<div v-if="!recommendedLoading" class="row p-0 d-flex">
<div v-if="posts.length" v-for="(s, index) in posts" :key="'rmki:'+index" class="col-4 p-1 p-sm-2 p-md-3 pt-0">
<a class="card info-overlay card-md-border-0" :href="s.url">
<div class="square">
<div v-if="s.sensitive" class="square-content">
@ -203,88 +132,21 @@
</div>
</a>
</div>
<div v-else class="col-12 d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
<div class="h2">No posts found :(</div>
</div>
</div>
<div v-else class="row d-flex align-items-center justify-content-center bg-light border" style="min-height: 40vh;">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</section>
<!-- <section class="pt-5 mb-5 section-explore">
<div class="profile-timeline pt-3">
<div class="row p-0 mt-5">
<div class="col-12 mb-3 d-flex justify-content-between align-items-center">
<p class="display-4 font-weight-bold mb-0">Recommended</p>
<!-- <div>
<div class="btn-group">
<button class="btn btn-dark py-1 font-weight-bold px-3 text-uppercase btn-sm">Today</button>
<button class="btn btn-outline-secondary py-1 font-weight-bold px-3 text-uppercase btn-sm">Weekly</button>
<button class="btn btn-outline-secondary py-1 font-weight-bold px-3 text-uppercase btn-sm">Monthly</button>
</div>
</div> - - ->
</div>
<div class="col-12 col-md-6">
<div class="mb-4">
<a class="card info-overlay card-md-border-0" :href="posts[20].url">
<div class="square">
<span v-if="posts[20].type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
<span v-if="posts[20].type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
<span v-if="posts[20].type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
<div class="square-content" v-bind:style="{ 'background-image': 'url(' + posts[20].thumb + ')' }">
</div>
</div>
</a>
</div>
</div>
<div class="col-12 col-md-6 row p-0 m-0">
<div v-for="(post, index) in posts.slice(21,25)" class="col-6" style="margin-bottom:1.8rem;">
<a class="card info-overlay card-md-border-0" :href="post.url">
<div class="square">
<span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
<span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
<span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
<div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
</div>
</div>
</a>
</div>
</div>
</div>
<div class="row p-0" style="display: flex;">
<div v-for="(post, index) in posts.slice(25, 29)" class="col-3 p-1 p-sm-2 p-md-3 pt-0">
<a class="card info-overlay card-md-border-0" :href="post.url">
<div class="square">
<span v-if="post.type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
<span v-if="post.type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
<span v-if="post.type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
<div class="square-content" v-bind:style="{ 'background-image': 'url(' + post.thumb + ')' }">
</div>
</div>
</a>
</div>
</div>
</div>
</section> -->
</div>
</div>
</template>
<style type="text/css" scoped>
.discover-bar::-webkit-scrollbar {
display: none;
}
.card-disc {
flex: 0 0 160px;
width:160px;
height:100px;
background-size: cover !important;
}
.post-icon {
color: #fff;
position:relative;
margin-top: 10px;
z-index: 9;
opacity: 0.6;
text-shadow: 3px 3px 16px #272634;
}
</style>
<script type="text/javascript">
export default {
data() {
@ -292,43 +154,34 @@
loaded: false,
config: window.App.config,
posts: {},
hashtags: {},
places: {},
trending: {},
trendingDaily: {},
trendingMonthly: {},
categories: {},
allCategories: {},
searchTerm: '',
trendingRange: 'daily'
trendingRange: 'daily',
trendingLoading: true,
recommendedLoading: true
}
},
mounted() {
this.fetchData();
this.fetchCategories();
this.loaded = true;
this.loadTrending();
this.loadTrendingHashtags();
this.loadTrendingPlaces();
this.fetchData();
axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
window._sharedData.curUser = res.data;
window.App.util.navatar();
});
},
methods: {
fetchData() {
if(!this.recommendedLoading) {
return;
}
axios.get('/api/pixelfed/v2/discover/posts')
.then((res) => {
this.posts = res.data.posts;
this.loaded = true;
});
axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
window._sharedData.curUser = res.data;
window.App.util.navatar();
});
},
fetchCategories() {
axios.get('/api/v2/discover/categories')
.then(res => {
this.allCategories = res.data;
this.categories = res.data;
this.recommendedLoading = false;
});
},
@ -341,11 +194,11 @@
loadTrending() {
if(this.trendingRange == 'daily' && this.trendingDaily.length) {
this.trending = this.trendingDaily;
return;
this.trendingLoading = false;
}
if(this.trendingRange == 'monthly' && this.trendingMonthly.length) {
this.trending = this.trendingMonthly;
return;
this.trendingLoading = false;
}
axios.get('/api/pixelfed/v2/discover/posts/trending', {
params: {
@ -360,28 +213,16 @@
this.trendingMonthly = res.data.filter(t => t.sensitive == false);
}
this.trending = res.data;
this.trendingLoading = false;
});
},
trendingRangeToggle(r) {
this.trendingLoading = true;
this.trendingRange = r;
this.loadTrending();
},
loadTrendingHashtags() {
axios.get('/api/pixelfed/v2/discover/posts/hashtags')
.then(res => {
this.hashtags = res.data;
});
},
loadTrendingPlaces() {
axios.get('/api/pixelfed/v2/discover/posts/places')
.then(res => {
this.places = res.data;
});
},
formatCount(s) {
return App.util.format.count(s);
}