From bb0182c1e16e674fba33b56fdeaa82dc22820634 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Sat, 9 May 2020 23:57:38 -0400 Subject: [PATCH] pull --- app/controllers/api/v1/groups_controller.rb | 2 +- app/controllers/api/v1/timelines/group_controller.rb | 6 ------ app/models/concerns/group_interactions.rb | 7 ------- app/models/group_account.rb | 2 +- app/models/status.rb | 5 +---- app/presenters/group_relationships_presenter.rb | 3 +-- app/serializers/rest/group_relationship_serializer.rb | 5 +---- ...200510034822_remove_unread_count_from_group_accounts.rb | 5 +++++ db/schema.rb | 7 +++++-- 9 files changed, 15 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20200510034822_remove_unread_count_from_group_accounts.rb diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb index 3ce89242..1684b133 100644 --- a/app/controllers/api/v1/groups_controller.rb +++ b/app/controllers/api/v1/groups_controller.rb @@ -16,7 +16,7 @@ class Api::V1::GroupsController < Api::BaseController when 'new' @groups = Group.where(is_archived: false).limit(24).order('created_at DESC').all when 'member' - @groups = Group.joins(:group_accounts).where(is_archived: false, group_accounts: { account: current_account }).order('group_accounts.unread_count DESC, group_accounts.id DESC').all + @groups = Group.joins(:group_accounts).where(is_archived: false, group_accounts: { account: current_account }).order('group_accounts.id DESC').all when 'admin' @groups = Group.joins(:group_accounts).where(is_archived: false, group_accounts: { account: current_account, role: :admin }).all end diff --git a/app/controllers/api/v1/timelines/group_controller.rb b/app/controllers/api/v1/timelines/group_controller.rb index b66abe2c..6ef63ef1 100644 --- a/app/controllers/api/v1/timelines/group_controller.rb +++ b/app/controllers/api/v1/timelines/group_controller.rb @@ -9,8 +9,6 @@ class Api::V1::Timelines::GroupController < Api::BaseController after_action :insert_pagination_headers, unless: -> { @statuses.empty? } def show - mark_as_unread - render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user.account_id) @@ -18,10 +16,6 @@ class Api::V1::Timelines::GroupController < Api::BaseController private - def mark_as_unread - GroupAccount.where(group: @group, account: current_account).update_all("unread_count = 0") - end - def set_group @group = Group.find(params[:id]) end diff --git a/app/models/concerns/group_interactions.rb b/app/models/concerns/group_interactions.rb index e15e1836..a0833165 100644 --- a/app/models/concerns/group_interactions.rb +++ b/app/models/concerns/group_interactions.rb @@ -13,19 +13,12 @@ module GroupInteractions follow_mapping(GroupAccount.where(group_id: target_group_ids, account_id: account_id, role: :admin), :group_id) end - def unread_count_map(target_group_ids, account_id) - unread_count_mapping(GroupAccount.where(group_id: target_group_ids, account_id: account_id), :unread_count) - end - private def follow_mapping(query, field) query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true } end - def unread_count_mapping(query, field) - query.pluck(:group_id, :unread_count).each_with_object({}) { |e, mapping| mapping[e[0]] = e[1] } - end end def accounts_for_local_distribution diff --git a/app/models/group_account.rb b/app/models/group_account.rb index b5aa62bc..0f059eee 100644 --- a/app/models/group_account.rb +++ b/app/models/group_account.rb @@ -9,10 +9,10 @@ # role :string # created_at :datetime not null # updated_at :datetime not null -# unread_count :integer default(0) # class GroupAccount < ApplicationRecord + self.ignored_columns = ["unread_count"] enum role: { admin: "admin" } belongs_to :group diff --git a/app/models/status.rb b/app/models/status.rb index 0938b9f3..6f4c94ce 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -26,6 +26,7 @@ # group_id :integer # quote_of_id :bigint(8) # revised_at :datetime +# markdown :text # class Status < ApplicationRecord @@ -268,7 +269,6 @@ class Status < ApplicationRecord after_create_commit :store_uri, if: :local? after_create_commit :update_statistics, if: :local? - after_create_commit :increase_group_unread_counts, if: Proc.new { |status| !status.group_id.nil? } around_create GabSocial::Snowflake::Callbacks @@ -555,7 +555,4 @@ class Status < ApplicationRecord end end - def increase_group_unread_counts - GroupAccount.where(group_id: group_id).where.not(account_id: account_id).update_all("unread_count = unread_count + 1") - end end diff --git a/app/presenters/group_relationships_presenter.rb b/app/presenters/group_relationships_presenter.rb index b6e217d5..55466cf6 100644 --- a/app/presenters/group_relationships_presenter.rb +++ b/app/presenters/group_relationships_presenter.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class GroupRelationshipsPresenter - attr_reader :member, :admin, :unread_count + attr_reader :member, :admin def initialize(group_ids, current_account_id, **options) @group_ids = group_ids.map { |a| a.is_a?(Group) ? a.id : a } @@ -9,7 +9,6 @@ class GroupRelationshipsPresenter @member = Group.member_map(@group_ids, @current_account_id) @admin = Group.admin_map(@group_ids, @current_account_id) - @unread_count = Group.unread_count_map(@group_ids, @current_account_id) end end \ No newline at end of file diff --git a/app/serializers/rest/group_relationship_serializer.rb b/app/serializers/rest/group_relationship_serializer.rb index a420ddbc..ce875681 100644 --- a/app/serializers/rest/group_relationship_serializer.rb +++ b/app/serializers/rest/group_relationship_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class REST::GroupRelationshipSerializer < ActiveModel::Serializer - attributes :id, :member, :admin, :unread_count + attributes :id, :member, :admin def id object.id.to_s @@ -15,7 +15,4 @@ class REST::GroupRelationshipSerializer < ActiveModel::Serializer instance_options[:relationships].admin[object.id] ? true : false end - def unread_count - instance_options[:relationships].unread_count[object.id] || 0 - end end diff --git a/db/migrate/20200510034822_remove_unread_count_from_group_accounts.rb b/db/migrate/20200510034822_remove_unread_count_from_group_accounts.rb new file mode 100644 index 00000000..bb9c6d59 --- /dev/null +++ b/db/migrate/20200510034822_remove_unread_count_from_group_accounts.rb @@ -0,0 +1,5 @@ +class RemoveUnreadCountFromGroupAccounts < ActiveRecord::Migration[5.2] + def change + safety_assured { remove_column :group_accounts, :unread_count, :integer } + end +end diff --git a/db/schema.rb b/db/schema.rb index 54db4f22..ca6dc28b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_04_30_154012) do +ActiveRecord::Schema.define(version: 2020_05_10_034822) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -327,7 +327,6 @@ ActiveRecord::Schema.define(version: 2020_04_30_154012) do t.string "role" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "unread_count", default: 0 t.index ["account_id", "group_id"], name: "index_group_accounts_on_account_id_and_group_id", unique: true t.index ["account_id"], name: "index_group_accounts_on_account_id" t.index ["group_id", "account_id"], name: "index_group_accounts_on_group_id_and_account_id" @@ -400,7 +399,11 @@ ActiveRecord::Schema.define(version: 2020_04_30_154012) do create_table "list_accounts", force: :cascade do |t| t.bigint "list_id", null: false t.bigint "account_id", null: false +<<<<<<< HEAD t.bigint "follow_id", default: nil +======= + t.bigint "follow_id", default: 1 +>>>>>>> f3c3a66e6... Removed unread_count from group_accounts t.index ["account_id", "list_id"], name: "index_list_accounts_on_account_id_and_list_id", unique: true t.index ["follow_id"], name: "index_list_accounts_on_follow_id" t.index ["list_id", "account_id"], name: "index_list_accounts_on_list_id_and_account_id"