Skip to content

Deprecate answers model #11308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/api/srch/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Search < Grape::API
doc_type: 'QUESTIONS',
doc_url: model.path(:question),
doc_title: model.title,
score: model.answers.length
score: model.comments.length
)
end
DocList.new(results_list.flatten, search_request)
Expand Down Expand Up @@ -257,7 +257,7 @@ class Search < Grape::API
doc_type: 'QUESTIONS',
doc_url: model.path(:question),
doc_title: model.title,
score: model.answers.length
score: model.comments.length
)
end

Expand Down Expand Up @@ -320,7 +320,7 @@ class Search < Grape::API
doc_title: model.title,
doc_author: model.user.username,
doc_image_url: model.images.empty? ? 0 : model.images.first.path,
score: model.answers.length,
score: model.comments.length,
latitude: model.lat,
longitude: model.lon,
blurred: model.blurred?,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def set_locale
end

def comments_node_and_path
@node = @comment.aid == 0 ? @comment.node : @comment.answer.node
@node = @comment.node

@path = params[:type] && params[:type] == 'question' ? @node.path(:question) : @node.path
end
Expand Down
12 changes: 2 additions & 10 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,14 @@ def activity
# group by day: http://stackoverflow.com/questions/5970938/group-by-day-from-timestamp
comments = comments.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == 'production'
comments = comments.to_a # ensure it can be serialized for caching
answer_comments = Comment.joins(:answer, :user)
.order('timestamp DESC')
.where('timestamp - answers.created_at > ?', 86_400)
.limit(20)
.group(['answers.id', 'comments.cid']) # ONLY_FULL_GROUP_BY, issue #3120
answer_comments = answer_comments.group('DATE(FROM_UNIXTIME(timestamp))') if Rails.env == 'production'
answer_comments = answer_comments.to_a # ensure it can be serialized for caching
activity = (notes + wikis + comments + answer_comments).sort_by(&:created_at).reverse
activity = (notes + wikis + comments).sort_by(&:created_at).reverse
response = [
activity,
blog,
notes,
wikis,
revisions,
comments,
answer_comments
comments
]
response
end
Expand Down
35 changes: 0 additions & 35 deletions app/models/answer.rb

This file was deleted.

11 changes: 5 additions & 6 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Comment < ApplicationRecord

belongs_to :node, foreign_key: 'nid', touch: true, counter_cache: true
belongs_to :user, foreign_key: 'uid'
belongs_to :answer, foreign_key: 'aid'
has_many :likes, as: :likeable

has_many :replied_comments, class_name: "Comment", foreign_key: 'reply_to', dependent: :destroy
Expand All @@ -21,7 +20,7 @@ class Comment < ApplicationRecord
def self.inheritance_column
'rails_type'
end

def self.search(query)
Comment.where('MATCH(comment) AGAINST(?)', query)
.where(status: 1)
Expand Down Expand Up @@ -90,7 +89,7 @@ def next_thread
end

def parent
aid.zero? ? node : answer&.node
node
end

def status_value
Expand Down Expand Up @@ -155,14 +154,14 @@ def notify(current_user)
uids = uids_to_notify - already
uids+= current_user.followers.collect(&:uid)
uids.uniq!

# Send Browser Notification Using Action Cable
notify_user_ids = uids_to_notify + already
notify_user_ids = notify_user_ids.uniq
send_browser_notification notify_user_ids

uids = uids.select { |i| i != 0 } # remove bad comments (some early ones lack uid)

notify_users(uids, current_user)
notify_tag_followers(already + uids)
end
Expand Down
3 changes: 1 addition & 2 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def updated_month
has_many :drupal_content_field_map_editor, foreign_key: 'nid' # , dependent: :destroy # re-enable in Rails 5
has_many :images, foreign_key: :nid
has_many :node_selections, foreign_key: :nid, dependent: :destroy
has_many :answers, foreign_key: :nid, dependent: :destroy

belongs_to :user, foreign_key: 'uid'

Expand Down Expand Up @@ -639,7 +638,7 @@ def self.for_tagname_and_type(tagname, type = 'note', options = {})
def self.for_wildcard_tagname_and_type(tagname, type = 'note')
search_term = tagname[0..-2] + '%'
Node.where(status: 1, type: type)
.includes(:revision, :tag, :answers)
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name LIKE (?) OR term_data.parent LIKE (?)', search_term, search_term)
end
Expand Down
7 changes: 2 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module Frequency
has_many :following_users, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower
has_many :likes
has_many :answers, foreign_key: :uid
has_many :answer_selections, foreign_key: :user_id
has_many :revisions, through: :node
has_many :comments, foreign_key: :uid
Expand Down Expand Up @@ -436,11 +435,10 @@ def find_by_username_case_insensitive(username)
# all users who've posted a node, comment, or answer in the given period
def contributor_count_for(start_time, end_time)
notes = Node.where(type: 'note', status: 1, created: start_time.to_i..end_time.to_i).pluck(:uid)
answers = Answer.where(created_at: start_time..end_time).pluck(:uid)
questions = Node.questions.where(status: 1, created: start_time.to_i..end_time.to_i).pluck(:uid)
comments = Comment.where(timestamp: start_time.to_i..end_time.to_i).pluck(:uid)
revisions = Revision.where(status: 1, timestamp: start_time.to_i..end_time.to_i).pluck(:uid)
contributors = (notes + answers + questions + comments + revisions).compact.uniq.size
contributors = (notes + questions + comments + revisions).compact.uniq.size
contributors
end

Expand All @@ -467,12 +465,11 @@ def create_with_omniauth(auth)

def count_all_time_contributor
notes = Node.where(type: 'note', status: 1).pluck(:uid)
answers = Answer.pluck(:uid)
questions = Node.questions.where(status: 1).pluck(:uid)
comments = Comment.pluck(:uid)
revisions = Revision.where(status: 1).pluck(:uid)

(notes + answers + questions + comments + revisions).compact.uniq.size
(notes + questions + comments + revisions).compact.uniq.size
end

def watching_location(nwlat, selat, nwlng, selng)
Expand Down
1 change: 0 additions & 1 deletion app/views/home/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<% cache('feature_home-intro', skip_digest: true) do %>
<%= feature("home-intro") %>
<% end %>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i see in the final diff nothing has changed. Thank you, just checking! Merging!

<div class="container">

<div class="projects">
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/_questions_shadow.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div>
<div class="answer">
<% if params[:controller] == 'questions' %>
<a class="peopleResponse" href="<%= node.path(:question) %>#answers" title="Answers"><%= node.answers.length %> <%=translation('questions._questions_shadow.people_responded')%></a>
<a class="peopleResponse" href="<%= node.path(:question) %>#answers" title="Answers"><%= node.comments.length %> <%=translation('questions._questions_shadow.people_responded')%></a>
<% end %>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220726161355_drop_answers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropAnswers < ActiveRecord::Migration[5.2]
def change
drop_table :answers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

end
end
19 changes: 0 additions & 19 deletions test/fixtures/answers.yml

This file was deleted.

10 changes: 2 additions & 8 deletions test/fixtures/comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ moderator:

answer_comment_one:
uid: 1
nid: 0
aid: 1
nid: 56
status: 1
comment: Answer comment one
timestamp: <%= Time.now.to_i + 7 %>

answer_comment_two:
uid: 2
nid: 0
aid: 1
nid: 56
status: 1
comment: Answer comment two
timestamp: <%= Time.now.to_i + 8 %>
Expand All @@ -75,7 +73,6 @@ wiki_comment:
question:
uid: 1
nid: 8
aid: 0
status: 1
comment: Question comment
timestamp: <%= Time.now.to_i + 9 %>
Expand Down Expand Up @@ -104,7 +101,6 @@ comment_status_4:
question_one:
uid: 2
nid: 8
aid: 0
status: 1
comment: Question comment one
timestamp: <%= Time.now.to_i + 11 %>
Expand All @@ -113,7 +109,6 @@ question_one:
question_callout:
uid: 2
nid: 8
aid: 0
status: 1
comment: Hey, @bob nice question
timestamp: <%= Time.now.to_i + 12 %>
Expand All @@ -122,7 +117,6 @@ question_callout:
question_tag:
uid: 2
nid: 8
aid: 0
status: 1
comment: 'Question #everything'
timestamp: <%= Time.now.to_i + 13 %>
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,16 @@ email:
type: "note"
cached_likes: 0
slug: "note-email-links"

# Node to link comments with no parent nodes, so that other tests don't fail
dummy_node:
nid: 56
uid: 2
title: "Dummy Node"
path: "/notes/jeff/12-23-2020/dummy-node"
created: <%= DateTime.new(2020,12,23).to_i %>
changed: <%= DateTime.new(2020,12,23).to_i %>
status: 8 # Intentional status so that other tests do not fail.
type: "note"
cached_likes: 0
slug: "note-dummy-node"
6 changes: 3 additions & 3 deletions test/functional/api/search_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def app
end

test 'search Tag Nearby Nodes functionality with a valid query' do
get '/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=176.5'
get "/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=176.5"
assert last_response.ok?

# Expected search pattern
Expand Down Expand Up @@ -178,7 +178,7 @@ def app
end

test 'search Tag Nearby Nodes functionality with a valid query and specific period' do
get '/api/srch/taglocations?nwlat=171.0&selat=0.0&nwlng=0.0&selng=174.8&sort_by=recent&order_direction=ASC&to=2018-08-16'
get "/api/srch/taglocations?nwlat=171.0&selat=0.0&nwlng=0.0&selng=174.8&sort_by=recent&order_direction=ASC&to=2018-08-16" # Very weird Test failing here
assert last_response.ok?

# Expected search pattern
Expand All @@ -204,7 +204,7 @@ def app
end

test 'search Tag Nearby Nodes functionality with a valid query and from date greater then to date' do
get '/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=180.0&sort_by=recent&order_direction=ASC&from=2018-08-16&to=2018-07-31'
get "/api/srch/taglocations?nwlat=180.0&selat=0.0&nwlng=0.0&selng=180.0&sort_by=recent&order_direction=ASC&from=2018-08-16&to=2018-07-31"
assert last_response.ok?

# Expected search pattern
Expand Down
2 changes: 1 addition & 1 deletion test/functional/comment_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def teardown
post :update, params: { id: comment.id, body: new_comment_body, type: 'question' }
comment.reload
assert_equal new_comment_body, comment.comment
assert_redirected_to comment.answer.node.path(:question) + '?_=' + Time.now.to_i.to_s
assert_redirected_to comment.node.path(:question) + '?_=' + Time.now.to_i.to_s
assert_equal flash[:notice], 'Comment updated.'
end

Expand Down
2 changes: 1 addition & 1 deletion test/functional/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setup

get :home
assert_response :success
assert_select "title", Sanitize.clean('&#127880;') + (" Public Lab: #{title}")
assert_select "title", Sanitize.clean('&#127880;') + (" Public Lab: #{title}") # Test failing here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops just need to remove this comment!

end

test 'home should redirect to dashboard if logged in' do
Expand Down
5 changes: 0 additions & 5 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -803,17 +803,12 @@ def test_get_rss_feed
UserSession.create(users(:moderator))
node = nodes(:question)
node.save
answer1 = answers(:one)
answer1.save
answer2 = answers(:two)
answer2.save
n_count = Node.count

post :delete, params: { id: node.id }, xhr: true

assert_response :success
assert_equal Node.count, n_count - 1
assert_equal Answer.count, 0
end

test 'moderator can publish the draft' do
Expand Down
2 changes: 1 addition & 1 deletion test/functional/questions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setup
assert_response :success
assert_equal assigns(:title), 'Unanswered questions'
assert_not_nil assigns(:questions)
assert_equal assigns(:questions).first.answers.length, 0
assert_equal assigns(:questions).first.comments.length, 0
assert_template :index
end

Expand Down
2 changes: 1 addition & 1 deletion test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def teardown

assert_response :success
assert_template :index
assert_select "title", Sanitize.clean('&#127880;') + (" Public Lab: Popular wiki pages")
assert_select "title", Sanitize.clean('&#127880;') + (" Public Lab: Popular wiki pages") # Test failing here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too!

end

test 'should display well liked wiki pages' do
Expand Down
2 changes: 0 additions & 2 deletions test/unit/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ def setup
end

test 'should create comments for answers' do
answer = answers(:one)
comment = Comment.new(
uid: users(:bob).id,
aid: answer.id,
comment: 'Test comment'
)
assert comment.save
Expand Down
Loading