Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/4875'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jun 9, 2024
2 parents c93aa80 + a4d3d32 commit b02d0b9
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/models/diary_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#

class DiaryComment < ApplicationRecord
belongs_to :user
belongs_to :user, :counter_cache => true
belongs_to :diary_entry

scope :visible, -> { where(:visible => true) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/note_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class NoteComment < ApplicationRecord
belongs_to :note, :touch => true
belongs_to :author, :class_name => "User", :optional => true
belongs_to :author, :class_name => "User", :optional => true, :counter_cache => true

validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :only_integer => true }
Expand Down
60 changes: 31 additions & 29 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
#
# Table name: users
#
# email :string not null
# id :bigint(8) not null, primary key
# pass_crypt :string not null
# creation_time :datetime not null
# display_name :string default(""), not null
# data_public :boolean default(FALSE), not null
# description :text default(""), not null
# home_lat :float
# home_lon :float
# home_zoom :integer default(3)
# pass_salt :string
# email_valid :boolean default(FALSE), not null
# new_email :string
# creation_ip :string
# languages :string
# status :enum default("pending"), not null
# terms_agreed :datetime
# consider_pd :boolean default(FALSE), not null
# auth_uid :string
# preferred_editor :string
# terms_seen :boolean default(FALSE), not null
# description_format :enum default("markdown"), not null
# changesets_count :integer default(0), not null
# traces_count :integer default(0), not null
# diary_entries_count :integer default(0), not null
# image_use_gravatar :boolean default(FALSE), not null
# auth_provider :string
# home_tile :bigint(8)
# tou_agreed :datetime
# email :string not null
# id :bigint(8) not null, primary key
# pass_crypt :string not null
# creation_time :datetime not null
# display_name :string default(""), not null
# data_public :boolean default(FALSE), not null
# description :text default(""), not null
# home_lat :float
# home_lon :float
# home_zoom :integer default(3)
# pass_salt :string
# email_valid :boolean default(FALSE), not null
# new_email :string
# creation_ip :string
# languages :string
# status :enum default("pending"), not null
# terms_agreed :datetime
# consider_pd :boolean default(FALSE), not null
# auth_uid :string
# preferred_editor :string
# terms_seen :boolean default(FALSE), not null
# description_format :enum default("markdown"), not null
# changesets_count :integer default(0), not null
# traces_count :integer default(0), not null
# diary_entries_count :integer default(0), not null
# image_use_gravatar :boolean default(FALSE), not null
# auth_provider :string
# home_tile :bigint(8)
# tou_agreed :datetime
# diary_comments_count :integer default(0)
# note_comments_count :integer default(0)
#
# Indexes
#
Expand Down
6 changes: 5 additions & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<span class='badge count-number'><%= number_with_delimiter(current_user.changesets.size) %></span>
</li>
<li>
<%= link_to t(".my notes"), user_notes_path(@user) %>
<%= link_to t(".my notes"), user_notes_path(current_user) %>
<span class='badge count-number'><%= number_with_delimiter(current_user.note_comments.size) %></span>
</li>
<li>
<%= link_to t(".my traces"), :controller => "traces", :action => "mine" %>
Expand All @@ -26,6 +27,7 @@
</li>
<li>
<%= link_to t(".my comments"), diary_comments_path(current_user) %>
<span class='badge count-number'><%= number_with_delimiter(current_user.diary_comments.size) %></span>
</li>
<li>
<%= link_to t(".my settings"), edit_account_path %>
Expand Down Expand Up @@ -59,6 +61,7 @@
</li>
<li>
<%= link_to t(".notes"), user_notes_path(@user) %>
<span class='badge count-number'><%= number_with_delimiter(@user.note_comments.size) %></span>
</li>
<li>
<%= link_to t(".traces"), :controller => "traces", :action => "index", :display_name => @user.display_name %>
Expand All @@ -76,6 +79,7 @@
</li>
<li>
<%= link_to t(".comments"), diary_comments_path(@user) %>
<span class='badge count-number'><%= number_with_delimiter(@user.diary_comments.size) %></span>
</li>
<li>
<% if current_user and current_user.friends_with?(@user) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class AddNotesAndDiaryCommentsCounterCaches < ActiveRecord::Migration[7.1]
class DiaryComment < ApplicationRecord
end

class NoteComment < ApplicationRecord
end

class User < ApplicationRecord
end

def self.up
add_column :users, :diary_comments_count, :integer, :default => 0
add_column :users, :note_comments_count, :integer, :default => 0

users_with_diary_comments = DiaryComment.distinct.pluck(:user_id)
users_with_diary_comments.each do |user_id|
User.reset_counters(user_id, :diary_comments)
end

users_with_note_comments = NoteComment.where.not(:author_id => nil).distinct.pluck(:author_id)
users_with_note_comments.each do |author_id|
User.reset_counters(author_id, :note_comments)
end
end

def self.down
remove_column :users, :diary_comments_count
remove_column :users, :note_comments_count
end
end
5 changes: 4 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,9 @@ CREATE TABLE public.users (
image_use_gravatar boolean DEFAULT false NOT NULL,
auth_provider character varying,
home_tile bigint,
tou_agreed timestamp without time zone
tou_agreed timestamp without time zone,
diary_comments_count integer DEFAULT 0,
note_comments_count integer DEFAULT 0
);


Expand Down Expand Up @@ -3519,6 +3521,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('23'),
('22'),
('21'),
('20240605134916'),
('20240405083825'),
('20240307181018'),
('20240307180830'),
Expand Down

0 comments on commit b02d0b9

Please sign in to comment.