mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
Exclude extra cross-posts from main feed #206
This commit is contained in:
parent
52be7bad5d
commit
a588126190
1 changed files with 33 additions and 3 deletions
|
@ -116,9 +116,39 @@ def home_page(sort, view_filter):
|
|||
posts = posts.order_by(desc(Post.last_active))
|
||||
|
||||
# Pagination
|
||||
posts = posts.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50, error_out=False)
|
||||
next_url = url_for('main.index', page=posts.next_num, sort=sort, view_filter=view_filter) if posts.has_next else None
|
||||
prev_url = url_for('main.index', page=posts.prev_num, sort=sort, view_filter=view_filter) if posts.has_prev and page != 1 else None
|
||||
if view_filter == 'subscribed' and current_user.is_authenticated and sort == 'new':
|
||||
# use python list instead of DB query
|
||||
posts = posts.all()
|
||||
|
||||
# exclude extra cross-posts from feed
|
||||
already_seen = []
|
||||
limit = 100 if not low_bandwidth else 50
|
||||
#i = -1 # option 1: don't exclude cross-posts
|
||||
#i = limit - 1 # option 2: exclude cross-posts from the first page only
|
||||
i = (limit * 10) - 1 # option 3: exclude cross-posts across a 'magic number' of pages
|
||||
#i = len(posts) - 1 # option 4: exclude all cross-posts ever
|
||||
while i >= 0:
|
||||
if not posts[i].cross_posts:
|
||||
i -= 1
|
||||
continue
|
||||
if posts[i].id in already_seen:
|
||||
posts.pop(i)
|
||||
else:
|
||||
already_seen.extend(posts[i].cross_posts)
|
||||
i -= 1
|
||||
|
||||
# paginate manually (can't use paginate())
|
||||
start = (page - 1) * limit
|
||||
end = start + limit
|
||||
posts = posts[start:end]
|
||||
next_page = page + 1 if len(posts) == limit else None
|
||||
previous_page = page - 1 if page != 1 else None
|
||||
next_url = url_for('main.index', page=next_page, sort=sort, view_filter=view_filter) if next_page else None
|
||||
prev_url = url_for('main.index', page=previous_page, sort=sort, view_filter=view_filter) if previous_page else None
|
||||
else:
|
||||
posts = posts.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50, error_out=False)
|
||||
next_url = url_for('main.index', page=posts.next_num, sort=sort, view_filter=view_filter) if posts.has_next else None
|
||||
prev_url = url_for('main.index', page=posts.prev_num, sort=sort, view_filter=view_filter) if posts.has_prev and page != 1 else None
|
||||
|
||||
# Active Communities
|
||||
active_communities = Community.query.filter_by(banned=False)
|
||||
|
|
Loading…
Add table
Reference in a new issue