Skip to content

Commit

Permalink
Remove featured number usage from articles (forem#18510)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdocr authored Sep 28, 2022
1 parent 5fad13f commit c57acc2
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 51 deletions.
5 changes: 2 additions & 3 deletions app/controllers/admin/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ArticlesController < Admin::ApplicationController
approved
email_digest_eligible
main_image_background_hex_color
featured_number
user_id
co_author_ids_list
published_at].freeze
Expand Down Expand Up @@ -114,10 +113,10 @@ def articles_mixed
def articles_featured
Article.published.or(Article.where(published_from_feed: true))
.featured
.where("featured_number > ?", Time.current.to_i)
.where("published_at > ?", Time.current)
.includes(:user)
.limited_columns_internal_select
.order(featured_number: :desc)
.order(published_at: :desc)
end

def article_params
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/article_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def co_author_name_and_path

# Used in determining when to bust additional routes for an Article's comments
def discussion?
cached_tag_list_array.include?("discuss") && featured_number.to_i > 35.hours.ago.to_i
cached_tag_list_array.include?("discuss") && published_at.to_i > 35.hours.ago.to_i
end

def pinned?
Expand Down
2 changes: 1 addition & 1 deletion app/lib/black_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def calculate_bonus_score(body_markdown)
end

def last_mile_hotness_calc(article)
score_from_epoch = article.featured_number.to_i - OUR_EPOCH_NUMBER # Approximate time of publish - epoch time
score_from_epoch = article.published_at.to_i - OUR_EPOCH_NUMBER # Approximate time of publish - epoch time
(score_from_epoch / 1000) +
([article.score, 650].min * 2) +
([article.comment_score, 650].min * 2)
Expand Down
13 changes: 4 additions & 9 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ def self.unique_url_error
:main_image, :main_image_background_hex_color, :updated_at,
:video, :user_id, :organization_id, :video_source_url, :video_code,
:video_thumbnail_url, :video_closed_caption_track_url, :social_image,
:published_from_feed, :crossposted_at, :published_at, :featured_number,
:created_at, :body_markdown, :email_digest_eligible, :processed_html, :co_author_ids)
:published_from_feed, :crossposted_at, :published_at, :created_at,
:body_markdown, :email_digest_eligible, :processed_html, :co_author_ids)
}

scope :sorting, lambda { |value|
Expand Down Expand Up @@ -608,7 +608,7 @@ def skip_indexing?
(score < Settings::UserExperience.index_minimum_score &&
user.comments_count < 1 &&
!featured) ||
featured_number.to_i < 1_500_000_000 ||
published_at.to_i < 1_500_000_000 ||
score < -1
end

Expand Down Expand Up @@ -894,7 +894,6 @@ def set_cached_entities
end

def set_all_dates
set_featured_number
set_crossposted_at
set_last_comment_at
set_nth_published_at
Expand All @@ -904,10 +903,6 @@ def set_published_date
self.published_at = Time.current if published && published_at.blank?
end

def set_featured_number
self.featured_number = Time.current.to_i if featured_number.blank? && published
end

def set_crossposted_at
self.crossposted_at = Time.current if published && crossposted_at.blank? && published_from_feed
end
Expand All @@ -930,7 +925,7 @@ def set_nth_published_at
end

def title_to_slug
"#{Sterile.sluggerize(title)}-#{rand(100_000).to_s(26)}"
"#{Sterile.sluggerize(title)}-#{rand(100_000).to_s(26)}" # rubocop:disable Rails/ToSWithArgument
end

def touch_actor_latest_article_updated_at(destroying: false)
Expand Down
4 changes: 2 additions & 2 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ def calculate_hotness_score
# FROM articles
# WHERE
# (cached_tag_list ~ '[[:<:]]javascript[[:>:]]')
# AND (articles.featured_number > 1639594999)
# AND (articles.published_at > 7.days.ago)
#
# Due to the construction of the query, there will be one entry.
# Furthermore, we need to first convert to an array then call
# `.first`. The ActiveRecord query handler is ill-prepared to
# call "first" on this.
score_attributes = Article.cached_tagged_with(name)
.where("articles.featured_number > ?", 7.days.ago.to_i)
.where("articles.published_at > ?", 7.days.ago)
.select("(SUM(comments_count) * 14 + SUM(score)) AS partial_score, COUNT(id) AS article_count")
.to_a
.first
Expand Down
8 changes: 4 additions & 4 deletions app/services/article_api_index_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def tag_articles
articles = published_articles_with_users_and_organizations.cached_tagged_with(tag)

articles = if Tag.find_by(name: tag)&.requires_approval
articles.approved.order(featured_number: :desc)
articles.approved.order(published_at: :desc)
elsif top.present?
articles.where("published_at > ?", top.to_i.days.ago)
.order(public_reactions_count: :desc)
Expand Down Expand Up @@ -104,12 +104,12 @@ def state_articles(state)
articles = case state
when "fresh"
articles.where(
"public_reactions_count < ? AND featured_number > ? AND score > ?", 2, 7.hours.ago.to_i, -2
"public_reactions_count < ? AND published_at > ? AND score > ?", 2, 7.hours.ago, -2
)
when "rising"
articles.where(
"public_reactions_count > ? AND public_reactions_count < ? AND featured_number > ?",
19, 33, 3.days.ago.to_i
"public_reactions_count > ? AND public_reactions_count < ? AND published_at > ?",
19, 33, 3.days.ago
)
when "recent"
articles.order(published_at: :desc)
Expand Down
2 changes: 1 addition & 1 deletion app/services/articles/suggest_stickies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def apply_common_scope(scope:, tags:)
.limited_column_select
.where.not(id: article.id)
.not_authored_by(article.user_id)
.where("featured_number > ?", 5.days.ago.to_i)
.where("published_at > ?", 5.days.ago)
.order(Arel.sql("RANDOM()"))
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/edge_cache/bust_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def self.paths_for(article, &block)
end

def self.bust_home_pages(cache_bust, article)
if article.featured_number.to_i > Time.current.to_i
if article.published_at.to_i > Time.current.to_i
cache_bust.call("/")
cache_bust.call("?i=i")
end

if article.video.present? && article.featured_number.to_i > 10.days.ago.to_i
if article.video.present? && article.published_at.to_i > 10.days.ago.to_i
cache_bust.call("/videos")
cache_bust.call("/videos?i=i")
end
Expand Down
9 changes: 0 additions & 9 deletions app/views/admin/articles/_individual_article.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,6 @@
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
<input type="hidden" name="_method" value="patch" />
<div class="flex gap-4">
<div class="crayons-field flex-1">
<label for="featured_number_<%= article.id %>" class="crayons-field__label">Featured number</label>
<input id="featured_number_<%= article.id %>"
class="crayons-textfield"
name="article[featured_number]"
value="<%= article.featured_number %>"
data-article-target="featuredNumber">
</div>

<div class="crayons-field flex-1">
<label for="author_id_<%= article.id %>" class="crayons-field__label">Author ID</label>
<input id="author_id_<%= article.id %>" class="crayons-textfield" size="6" name="article[user_id]"
Expand Down
8 changes: 4 additions & 4 deletions spec/decorators/article_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ def create_article(*args)
expect(article.decorate.discussion?).to be false
end

it "returns false if featured number is less than 35 hours ago" do
it "returns false if published_at is less than 35 hours ago" do
Timecop.freeze(Time.current) do
article.featured_number = 35.hours.ago.to_i - 1
article.published_at = 35.hours.ago - 1
expect(article.decorate.discussion?).to be false
end
end

it "returns true if it's tagged with discuss and has a feature number greater than 35 hours ago" do
it "returns true if it's tagged with discuss and has a published_at greater than 35 hours ago" do
Timecop.freeze(Time.current) do
article.cached_tag_list = "welcome, discuss"
article.featured_number = 35.hours.ago.to_i + 1
article.published_at = 35.hours.ago + 1
expect(article.decorate.discussion?).to be true
end
end
Expand Down
13 changes: 0 additions & 13 deletions spec/models/article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,19 +688,6 @@ def build_and_validate_article(*args)
end
end

describe "#featured_number" do
it "is updated if approved when already true" do
body = "---\ntitle: Hellohnnnn#{rand(1000)}\npublished: true\ntags: hiring\n---\n\nHello"
article.update(body_markdown: body, approved: true)

Timecop.travel(1.second.from_now) do
article.update(body_markdown: "#{body}s")
end

expect(article.featured_number).not_to eq(article.updated_at.to_i)
end
end

describe "#slug" do
let(:title) { "hey This' is$ a SLUG" }
let(:article0) { build(:article, title: title, published: false) }
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/api/v0/articles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
end

it "returns rising articles" do
article.update_columns(public_reactions_count: 32, score: 1, featured_number: 2.days.ago.to_i)
article.update_columns(public_reactions_count: 32, score: 1, published_at: 2.days.ago)

get api_articles_path(state: "rising")
expect(response.parsed_body.size).to eq(1)
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/api/v1/articles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
end

it "returns rising articles" do
article.update_columns(public_reactions_count: 32, score: 1, featured_number: 2.days.ago.to_i)
article.update_columns(public_reactions_count: 32, score: 1, published_at: 2.days.ago)

get api_articles_path(state: "rising"), headers: headers
expect(response.parsed_body.size).to eq(1)
Expand Down

0 comments on commit c57acc2

Please sign in to comment.