Merge remote-tracking branch 'upstream/pull/4875'

This commit is contained in:
Tom Hughes 2024-06-09 14:42:50 +01:00
commit b02d0b9b22
6 changed files with 72 additions and 33 deletions

View file

@ -23,7 +23,7 @@
# #
class DiaryComment < ApplicationRecord class DiaryComment < ApplicationRecord
belongs_to :user belongs_to :user, :counter_cache => true
belongs_to :diary_entry belongs_to :diary_entry
scope :visible, -> { where(:visible => true) } scope :visible, -> { where(:visible => true) }

View file

@ -26,7 +26,7 @@
class NoteComment < ApplicationRecord class NoteComment < ApplicationRecord
belongs_to :note, :touch => true 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 }, validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :only_integer => true } :numericality => { :on => :update, :only_integer => true }

View file

@ -2,35 +2,37 @@
# #
# Table name: users # Table name: users
# #
# email :string not null # email :string not null
# id :bigint(8) not null, primary key # id :bigint(8) not null, primary key
# pass_crypt :string not null # pass_crypt :string not null
# creation_time :datetime not null # creation_time :datetime not null
# display_name :string default(""), not null # display_name :string default(""), not null
# data_public :boolean default(FALSE), not null # data_public :boolean default(FALSE), not null
# description :text default(""), not null # description :text default(""), not null
# home_lat :float # home_lat :float
# home_lon :float # home_lon :float
# home_zoom :integer default(3) # home_zoom :integer default(3)
# pass_salt :string # pass_salt :string
# email_valid :boolean default(FALSE), not null # email_valid :boolean default(FALSE), not null
# new_email :string # new_email :string
# creation_ip :string # creation_ip :string
# languages :string # languages :string
# status :enum default("pending"), not null # status :enum default("pending"), not null
# terms_agreed :datetime # terms_agreed :datetime
# consider_pd :boolean default(FALSE), not null # consider_pd :boolean default(FALSE), not null
# auth_uid :string # auth_uid :string
# preferred_editor :string # preferred_editor :string
# terms_seen :boolean default(FALSE), not null # terms_seen :boolean default(FALSE), not null
# description_format :enum default("markdown"), not null # description_format :enum default("markdown"), not null
# changesets_count :integer default(0), not null # changesets_count :integer default(0), not null
# traces_count :integer default(0), not null # traces_count :integer default(0), not null
# diary_entries_count :integer default(0), not null # diary_entries_count :integer default(0), not null
# image_use_gravatar :boolean default(FALSE), not null # image_use_gravatar :boolean default(FALSE), not null
# auth_provider :string # auth_provider :string
# home_tile :bigint(8) # home_tile :bigint(8)
# tou_agreed :datetime # tou_agreed :datetime
# diary_comments_count :integer default(0)
# note_comments_count :integer default(0)
# #
# Indexes # Indexes
# #

View file

@ -14,7 +14,8 @@
<span class='badge count-number'><%= number_with_delimiter(current_user.changesets.size) %></span> <span class='badge count-number'><%= number_with_delimiter(current_user.changesets.size) %></span>
</li> </li>
<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>
<li> <li>
<%= link_to t(".my traces"), :controller => "traces", :action => "mine" %> <%= link_to t(".my traces"), :controller => "traces", :action => "mine" %>
@ -26,6 +27,7 @@
</li> </li>
<li> <li>
<%= link_to t(".my comments"), diary_comments_path(current_user) %> <%= 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>
<li> <li>
<%= link_to t(".my settings"), edit_account_path %> <%= link_to t(".my settings"), edit_account_path %>
@ -59,6 +61,7 @@
</li> </li>
<li> <li>
<%= link_to t(".notes"), user_notes_path(@user) %> <%= link_to t(".notes"), user_notes_path(@user) %>
<span class='badge count-number'><%= number_with_delimiter(@user.note_comments.size) %></span>
</li> </li>
<li> <li>
<%= link_to t(".traces"), :controller => "traces", :action => "index", :display_name => @user.display_name %> <%= link_to t(".traces"), :controller => "traces", :action => "index", :display_name => @user.display_name %>
@ -76,6 +79,7 @@
</li> </li>
<li> <li>
<%= link_to t(".comments"), diary_comments_path(@user) %> <%= link_to t(".comments"), diary_comments_path(@user) %>
<span class='badge count-number'><%= number_with_delimiter(@user.diary_comments.size) %></span>
</li> </li>
<li> <li>
<% if current_user and current_user.friends_with?(@user) %> <% if current_user and current_user.friends_with?(@user) %>

View file

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

View file

@ -1565,7 +1565,9 @@ CREATE TABLE public.users (
image_use_gravatar boolean DEFAULT false NOT NULL, image_use_gravatar boolean DEFAULT false NOT NULL,
auth_provider character varying, auth_provider character varying,
home_tile bigint, 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
); );
@ -3519,6 +3521,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('23'), ('23'),
('22'), ('22'),
('21'), ('21'),
('20240605134916'),
('20240405083825'), ('20240405083825'),
('20240307181018'), ('20240307181018'),
('20240307180830'), ('20240307180830'),