Skip to content

Commit

Permalink
Merge branch 'develop' into luap42/moderator-tools-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
trichoplax committed Oct 25, 2024
2 parents 71f62b7 + 78cbfb2 commit a5ab018
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 0 additions & 5 deletions app/models/community_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def suspended?
false
end

# All undeleted posts on this community by this user.
def post_count
Post.unscoped.where(community_id: community_id).where(user: user).undeleted.count
end

# Calculation functions for privilege scores
# These are quite expensive, so we'll cache them for a while
def post_score
Expand Down
1 change: 1 addition & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Post < ApplicationRecord
has_many :reactions

counter_culture :parent, column_name: proc { |model| model.deleted? ? nil : 'answer_count' }
counter_culture [:user, :community_user], column_name: proc { |model| model.deleted? ? nil : 'post_count' }

serialize :tags_cache, Array

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPostCountToCommunityUsers < ActiveRecord::Migration[7.0]
def change
add_column :community_users, :post_count, :integer, default: 0, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_04_05_113618) do
ActiveRecord::Schema[7.0].define(version: 2024_10_20_193053) do
create_table "abilities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "community_id"
t.string "name"
Expand Down Expand Up @@ -227,6 +227,7 @@
t.boolean "deleted", default: false, null: false
t.datetime "deleted_at", precision: nil
t.bigint "deleted_by_id"
t.integer "post_count", default: 0, null: false
t.index ["community_id"], name: "index_community_users_on_community_id"
t.index ["deleted_by_id"], name: "index_community_users_on_deleted_by_id"
t.index ["user_id"], name: "index_community_users_on_user_id"
Expand Down

0 comments on commit a5ab018

Please sign in to comment.