Updates to groups sorting
• Updates to groups sorting
This commit is contained in:
@@ -12,7 +12,8 @@ class Api::V1::GroupsController < Api::BaseController
|
||||
def index
|
||||
case current_tab
|
||||
when 'featured'
|
||||
@groups = Group.where(is_featured: true, is_archived: false).limit(100).all
|
||||
@groupIds = FetchGroupsService.new.call("featured")
|
||||
@groups = Group.where(id: @groupIds).limit(150).all
|
||||
when 'new'
|
||||
if !current_user
|
||||
render json: { error: 'This method requires an authenticated user' }, status: 422
|
||||
|
||||
@@ -62,7 +62,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
|
||||
|
||||
@groupIds = []
|
||||
if @collection_type == 'featured'
|
||||
@groupIds = Group.where(is_featured: true, is_archived: false).limit(100).all.pluck(:id)
|
||||
@groupIds = FetchGroupsService.new.call("featured")
|
||||
elsif @collection_type == 'member' && !current_user.nil?
|
||||
@groupIds = current_user.account.groups.pluck(:id)
|
||||
else
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '../actions/groups'
|
||||
import {
|
||||
GROUP_TIMELINE_SORTING_TYPE_TOP,
|
||||
GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_WEEKLY,
|
||||
GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_TODAY,
|
||||
GROUP_TIMELINE_SORTING_TYPE_NEWEST,
|
||||
} from '../constants'
|
||||
import getSortBy from '../utils/group_sort_by'
|
||||
@@ -54,7 +54,7 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
},
|
||||
setFeaturedTop() {
|
||||
dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_TOP))
|
||||
dispatch(setGroupTimelineTopSort(GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_WEEKLY))
|
||||
dispatch(setGroupTimelineTopSort(GROUP_TIMELINE_SORTING_TYPE_TOP_OPTION_TODAY))
|
||||
},
|
||||
setMemberNewest() {
|
||||
dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_NEWEST))
|
||||
|
||||
@@ -52,7 +52,7 @@ class GroupsPage extends PureComponent {
|
||||
|
||||
const tabs = !!me ? [
|
||||
{
|
||||
title: intl.formatMessage(dontShowChildren ? messages.myGroupsTimeline : messages.groups),
|
||||
title: intl.formatMessage(messages.myGroupsTimeline),
|
||||
to: '/groups',
|
||||
},
|
||||
{
|
||||
|
||||
22
app/services/fetch_groups_service.rb
Normal file
22
app/services/fetch_groups_service.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FetchGroupsService < BaseService
|
||||
def call(type)
|
||||
|
||||
if type == "featured"
|
||||
body = Redis.current.get("groups:featuredgroups")
|
||||
|
||||
if body.nil? || !body || body.empty?
|
||||
@groupIds = Group.where(is_featured: true, is_archived: false).limit(150).all.pluck(:id)
|
||||
|
||||
Redis.current.set("groups:featuredgroups", @groupIds.join(","))
|
||||
Redis.current.expire("groups:featuredgroups", 6.hours.seconds)
|
||||
|
||||
@groupIds
|
||||
else
|
||||
body.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user