Updated SortingQueryBuilder for ExploreTimeline, GroupCollectionTimeline, GroupTimeline
• Updated: - SortingQueryBuilder for ExploreTimeline, GroupCollectionTimeline, GroupTimeline • TODO - Test on a lot of data to ensure no repeats - Test reducers/timeline updates to appending and concating non status.id sorted results
This commit is contained in:
parent
7dd71a06ca
commit
620f50752f
@ -4,9 +4,7 @@ class Api::V1::Timelines::ExploreController < EmptyController
|
|||||||
before_action :set_sort_type
|
before_action :set_sort_type
|
||||||
before_action :set_statuses
|
before_action :set_statuses
|
||||||
|
|
||||||
after_action :insert_pagination_headers, unless: -> {
|
after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
|
||||||
@statuses.empty?
|
|
||||||
}
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if current_user
|
if current_user
|
||||||
@ -46,9 +44,11 @@ class Api::V1::Timelines::ExploreController < EmptyController
|
|||||||
|
|
||||||
def explore_statuses
|
def explore_statuses
|
||||||
if current_account
|
if current_account
|
||||||
SortingQueryBuilder.new.call(@sort_type, params[:max_id]).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) }
|
SortingQueryBuilder.new.call(@sort_type, nil, params[:page]).reject {|status|
|
||||||
|
FeedManager.instance.filter?(:home, status, current_account.id)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
SortingQueryBuilder.new.call(@sort_type, params[:max_id])
|
SortingQueryBuilder.new.call(@sort_type, nil, params[:page])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,9 +5,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
|
|||||||
before_action :set_sort_type
|
before_action :set_sort_type
|
||||||
before_action :set_statuses
|
before_action :set_statuses
|
||||||
|
|
||||||
after_action :insert_pagination_headers, unless: -> {
|
after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
|
||||||
@statuses.empty?
|
|
||||||
}
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if current_account
|
if current_account
|
||||||
@ -69,9 +67,11 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
if current_account
|
if current_account
|
||||||
SortingQueryBuilder.new.call(@sort_type, params[:max_id], @groupIds).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) }
|
SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page]).reject {|status|
|
||||||
|
FeedManager.instance.filter?(:home, status, current_account.id)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
SortingQueryBuilder.new.call(@sort_type, params[:max_id], @groupIds)
|
SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,9 +5,7 @@ class Api::V1::Timelines::GroupController < Api::BaseController
|
|||||||
before_action :set_sort_type
|
before_action :set_sort_type
|
||||||
before_action :set_statuses
|
before_action :set_statuses
|
||||||
|
|
||||||
after_action :insert_pagination_headers, unless: -> {
|
after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
|
||||||
@statuses.empty?
|
|
||||||
}
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if current_user
|
if current_user
|
||||||
@ -52,9 +50,11 @@ class Api::V1::Timelines::GroupController < Api::BaseController
|
|||||||
|
|
||||||
def group_statuses
|
def group_statuses
|
||||||
if current_account
|
if current_account
|
||||||
SortingQueryBuilder.new.call(@sort_type, params[:max_id], @group).reject { |status| FeedManager.instance.filter?(:home, status, current_account.id) }
|
SortingQueryBuilder.new.call(@sort_type, @group, params[:page]).reject {|status|
|
||||||
|
FeedManager.instance.filter?(:home, status, current_account.id)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
SortingQueryBuilder.new.call(@sort_type, params[:max_id], @group)
|
SortingQueryBuilder.new.call(@sort_type, @group, params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -230,8 +230,9 @@ export const expandHomeTimeline = ({ maxId } = {}, done = noop) => {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const expandExploreTimeline = ({ maxId, sortBy } = {}, done = noop) => {
|
export const expandExploreTimeline = ({ maxId, sortBy, page } = {}, done = noop) => {
|
||||||
return expandTimeline('explore', '/api/v1/timelines/explore', {
|
return expandTimeline('explore', '/api/v1/timelines/explore', {
|
||||||
|
page,
|
||||||
max_id: maxId,
|
max_id: maxId,
|
||||||
sort_by: sortBy,
|
sort_by: sortBy,
|
||||||
}, done)
|
}, done)
|
||||||
@ -303,10 +304,11 @@ export const expandListTimeline = (id, { maxId } = {}, done = noop) => {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const expandGroupTimeline = (id, { sortBy, maxId, onlyMedia } = {}, done = noop) => {
|
export const expandGroupTimeline = (id, { sortBy, maxId, onlyMedia, page } = {}, done = noop) => {
|
||||||
if (!id) return
|
if (!id) return
|
||||||
|
|
||||||
return expandTimeline(`group:${id}`, `/api/v1/timelines/group/${id}`, {
|
return expandTimeline(`group:${id}`, `/api/v1/timelines/group/${id}`, {
|
||||||
|
page,
|
||||||
sort_by: sortBy,
|
sort_by: sortBy,
|
||||||
max_id: maxId,
|
max_id: maxId,
|
||||||
only_media: onlyMedia
|
only_media: onlyMedia
|
||||||
@ -323,8 +325,9 @@ export const expandGroupFeaturedTimeline = (groupId, done = noop) => {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const expandGroupCollectionTimeline = (collectionType, { sortBy, maxId } = {}, done = noop) => {
|
export const expandGroupCollectionTimeline = (collectionType, { sortBy, maxId, page } = {}, done = noop) => {
|
||||||
return expandTimeline(`group_collection:${collectionType}`, `/api/v1/timelines/group_collection/${collectionType}`, {
|
return expandTimeline(`group_collection:${collectionType}`, `/api/v1/timelines/group_collection/${collectionType}`, {
|
||||||
|
page,
|
||||||
sort_by: sortBy,
|
sort_by: sortBy,
|
||||||
max_id: maxId,
|
max_id: maxId,
|
||||||
}, done)
|
}, done)
|
||||||
|
@ -23,9 +23,9 @@ import GroupSortBlock from '../components/group_sort_block'
|
|||||||
class ExploreTimeline extends React.PureComponent {
|
class ExploreTimeline extends React.PureComponent {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
//keep track of loads for if no user,
|
//keep track of page loads for if no user,
|
||||||
//only allow 2 loads before showing sign up msg
|
//only allow 2 page loads before showing sign up msg
|
||||||
loadCount: 0,
|
page: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -55,26 +55,23 @@ class ExploreTimeline extends React.PureComponent {
|
|||||||
sortByValue,
|
sortByValue,
|
||||||
sortByTopValue,
|
sortByTopValue,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { loadCount } = this.state
|
const { page } = this.state
|
||||||
|
|
||||||
if (!!maxId && !me) {
|
const newPage = !!maxId ? this.state.page + 1 : 1
|
||||||
this.setState({ loadCount: this.state.loadCount + 1 })
|
if (!!maxId && !me && page >= 2) return false
|
||||||
if (loadCount >= 2) return false
|
this.setState({ page: newPage })
|
||||||
} else if (!maxId && loadCount !== 0) {
|
|
||||||
this.setState({ loadCount: 0 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
||||||
const options = { sortBy, maxId }
|
const options = { sortBy, maxId, page: newPage }
|
||||||
|
|
||||||
this.props.onExpandExploreTimeline(options)
|
this.props.onExpandExploreTimeline(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { intl } = this.props
|
const { intl } = this.props
|
||||||
const { loadCount } = this.state
|
const { page } = this.state
|
||||||
|
|
||||||
const canLoadMore = loadCount < 2 && !me || !!me
|
const canLoadMore = page < 2 && !me || !!me
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -24,9 +24,9 @@ import GroupsCollection from './groups_collection'
|
|||||||
class GroupCollectionTimeline extends React.PureComponent {
|
class GroupCollectionTimeline extends React.PureComponent {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
//keep track of loads for if no user,
|
//keep track of page loads for if no user,
|
||||||
//only allow 2 loads before showing sign up msg
|
//only allow 2 page loads before showing sign up msg
|
||||||
loadCount: 0,
|
page: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -61,17 +61,14 @@ class GroupCollectionTimeline extends React.PureComponent {
|
|||||||
sortByValue,
|
sortByValue,
|
||||||
sortByTopValue,
|
sortByTopValue,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { loadCount } = this.state
|
const { page } = this.state
|
||||||
|
|
||||||
if (!!maxId && !me) {
|
const newPage = !!maxId ? this.state.page + 1 : 1
|
||||||
this.setState({ loadCount: this.state.loadCount + 1 })
|
if (!!maxId && !me && page >= 2) return false
|
||||||
if (loadCount >= 2) return false
|
this.setState({ page: newPage })
|
||||||
} else if (!maxId && loadCount !== 0) {
|
|
||||||
this.setState({ loadCount: 0 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
||||||
const options = { sortBy, maxId }
|
const options = { sortBy, maxId, page: newPage }
|
||||||
|
|
||||||
this.props.onExpandGroupCollectionTimeline(collectionType, options)
|
this.props.onExpandGroupCollectionTimeline(collectionType, options)
|
||||||
}
|
}
|
||||||
@ -82,7 +79,7 @@ class GroupCollectionTimeline extends React.PureComponent {
|
|||||||
intl,
|
intl,
|
||||||
hasNoGroupMembers,
|
hasNoGroupMembers,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { loadCount } = this.state
|
const { page } = this.state
|
||||||
|
|
||||||
const emptyMessage = !!me && collectionType === 'member' && hasNoGroupMembers ? (
|
const emptyMessage = !!me && collectionType === 'member' && hasNoGroupMembers ? (
|
||||||
<div className={[_s.d, _s.w100PC]}>
|
<div className={[_s.d, _s.w100PC]}>
|
||||||
@ -93,7 +90,7 @@ class GroupCollectionTimeline extends React.PureComponent {
|
|||||||
</div>
|
</div>
|
||||||
) : intl.formatMessage(messages.empty)
|
) : intl.formatMessage(messages.empty)
|
||||||
|
|
||||||
const canLoadMore = loadCount < 2 && !me || !!me
|
const canLoadMore = page < 2 && !me || !!me
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -25,9 +25,9 @@ import GroupSortBlock from '../components/group_sort_block'
|
|||||||
class GroupTimeline extends ImmutablePureComponent {
|
class GroupTimeline extends ImmutablePureComponent {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
//keep track of loads for if no user,
|
//keep track of page loads for if no user,
|
||||||
//only allow 2 loads before showing sign up msg
|
//only allow 2 page loads before showing sign up msg
|
||||||
loadCount: 0,
|
page: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -72,17 +72,19 @@ class GroupTimeline extends ImmutablePureComponent {
|
|||||||
sortByTopValue,
|
sortByTopValue,
|
||||||
onlyMedia,
|
onlyMedia,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { loadCount } = this.state
|
const { page } = this.state
|
||||||
|
|
||||||
if (!!maxId && !me) {
|
const newPage = !!maxId ? this.state.page + 1 : 1
|
||||||
this.setState({ loadCount: this.state.loadCount + 1 })
|
if (!!maxId && !me && page >= 2) return false
|
||||||
if (loadCount >= 2) return false
|
this.setState({ page: newPage })
|
||||||
} else if (!maxId && loadCount !== 0) {
|
|
||||||
this.setState({ loadCount: 0 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
||||||
this.props.onExpandGroupTimeline(groupId, { sortBy, maxId, onlyMedia })
|
this.props.onExpandGroupTimeline(groupId, {
|
||||||
|
sortBy,
|
||||||
|
maxId,
|
||||||
|
onlyMedia,
|
||||||
|
page: newPage,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -92,7 +94,7 @@ class GroupTimeline extends ImmutablePureComponent {
|
|||||||
intl,
|
intl,
|
||||||
groupPinnedStatusIds,
|
groupPinnedStatusIds,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { loadCount } = this.state
|
const { page } = this.state
|
||||||
|
|
||||||
if (typeof group === 'undefined') {
|
if (typeof group === 'undefined') {
|
||||||
return <ColumnIndicator type='loading' />
|
return <ColumnIndicator type='loading' />
|
||||||
@ -100,7 +102,7 @@ class GroupTimeline extends ImmutablePureComponent {
|
|||||||
return <ColumnIndicator type='missing' />
|
return <ColumnIndicator type='missing' />
|
||||||
}
|
}
|
||||||
|
|
||||||
const canLoadMore = loadCount < 2 && !me || !!me
|
const canLoadMore = page < 2 && !me || !!me
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SortingQueryBuilder < BaseService
|
class SortingQueryBuilder < BaseService
|
||||||
def call(sort_type, max_id = nil, group = nil)
|
def call(sort_type, group = nil, page = 1)
|
||||||
min_likes = 20
|
limit = 20
|
||||||
min_reblogs = 10
|
|
||||||
min_replies = 2
|
min_likes = 5
|
||||||
|
min_reblogs = 2
|
||||||
|
min_replies = 1
|
||||||
date_limit = 30.days.ago
|
date_limit = 30.days.ago
|
||||||
|
max_page = 8
|
||||||
|
|
||||||
case sort_type
|
case sort_type
|
||||||
when 'hot'
|
when 'hot'
|
||||||
@ -32,14 +35,35 @@ class SortingQueryBuilder < BaseService
|
|||||||
'top_all_time',
|
'top_all_time',
|
||||||
]
|
]
|
||||||
|
|
||||||
query = Status.unscoped.without_replies
|
if page.to_i > max_page
|
||||||
query = query.joins(:status_stat).order(top_order) unless ['newest'].include? sort_type
|
return []
|
||||||
|
end
|
||||||
|
|
||||||
|
if sort_type == 'newest'
|
||||||
|
query = Status.without_replies.without_reblogs
|
||||||
|
query = query.with_public_visibility if group.nil?
|
||||||
query = query.where('statuses.created_at > ?', date_limit)
|
query = query.where('statuses.created_at > ?', date_limit)
|
||||||
query = query.where(group: group) unless group.nil?
|
query = query.where(group: group) unless group.nil?
|
||||||
query = query.where('statuses.id > ? AND statuses.id <> ?', max_id, max_id) unless max_id.nil? || max_id.empty?
|
query = query.page(page.to_i)
|
||||||
query = query.limit(20)
|
query = query.per(limit)
|
||||||
|
return query
|
||||||
query
|
else
|
||||||
|
query = StatusStat.where('status_stats.created_at > ?', date_limit)
|
||||||
|
query = query.order(top_order) unless sort_type == 'recent'
|
||||||
|
query = query.order(updated_at: :desc) if sort_type == 'recent'
|
||||||
|
query = query.where('status.stats.replies_count > ?', min_replies) unless sort_type == 'recent'
|
||||||
|
query = query.where('status.stats.reblogs_count > ?', min_reblogs) unless sort_type == 'recent'
|
||||||
|
query = query.where('status.stats.favourites_count > ?', min_likes) unless sort_type == 'recent'
|
||||||
|
query = query.joins(:status)
|
||||||
|
query = query.where('statuses.reblog_of_id IS NULL')
|
||||||
|
query = query.where('statuses.in_reply_to_id IS NULL')
|
||||||
|
query = query.where('statuses.group_id': group) unless group.nil?
|
||||||
|
query = query.where('statuses.visibility': 0) if group.nil?
|
||||||
|
query = query.page(page)
|
||||||
|
query = query.per(limit)
|
||||||
|
query = query.map(&:status)
|
||||||
|
return query
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user