Updates to groups sorting

• Updates to groups sorting
This commit is contained in:
mgabdev 2020-08-08 13:08:48 -05:00
parent d3aa5ddf4b
commit 4a8cd0b585
8 changed files with 47 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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',
},
{

View 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

View File

@ -0,0 +1,8 @@
class AddIndexToStatusCreatedAt < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def change
add_index :statuses, :created_at, algorithm: :concurrently
add_index :statuses, :updated_at, algorithm: :concurrently
end
end

View File

@ -0,0 +1,7 @@
class AddIndexToUserCurrentSignInAt < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def change
add_index :users, :current_sign_in_at, algorithm: :concurrently
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_08_06_231714) do
ActiveRecord::Schema.define(version: 2020_08_08_170708) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
@ -775,12 +775,14 @@ ActiveRecord::Schema.define(version: 2020_08_06_231714) do
t.datetime "expires_at"
t.boolean "has_quote"
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc }
t.index ["created_at"], name: "index_statuses_on_created_at"
t.index ["group_id"], name: "index_statuses_on_group_id"
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
t.index ["quote_of_id"], name: "index_statuses_on_quote_of_id"
t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id"
t.index ["reply"], name: "index_statuses_on_reply"
t.index ["updated_at"], name: "index_statuses_on_updated_at"
t.index ["uri"], name: "index_statuses_on_uri", unique: true
end
@ -893,6 +895,7 @@ ActiveRecord::Schema.define(version: 2020_08_06_231714) do
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["created_at"], name: "index_users_on_created_at"
t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id"
t.index ["current_sign_in_at"], name: "index_users_on_current_sign_in_at"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unique_email"], name: "index_users_on_unique_email"