✂️✂️✂️ Remove boosted states from articles (legacy/dead code) (#14977)
* Remove boosted states from articles (legacy/dead code) * Fix indentation
This commit is contained in:
parent
1d62d30853
commit
b0a79da072
9 changed files with 11 additions and 121 deletions
|
|
@ -11,8 +11,6 @@ module Admin
|
|||
body_markdown
|
||||
approved
|
||||
email_digest_eligible
|
||||
boosted_additional_articles
|
||||
boosted_dev_digest_email
|
||||
main_image_background_hex_color
|
||||
featured_number
|
||||
user_id
|
||||
|
|
@ -26,8 +24,6 @@ module Admin
|
|||
when /top-/
|
||||
months_ago = params[:state].split("-")[1].to_i.months.ago
|
||||
@articles = articles_top(months_ago)
|
||||
when "boosted-additional-articles"
|
||||
@articles = articles_boosted_additional
|
||||
when "chronological"
|
||||
@articles = articles_chronological
|
||||
else
|
||||
|
|
@ -79,15 +75,6 @@ module Admin
|
|||
.per(50)
|
||||
end
|
||||
|
||||
def articles_boosted_additional
|
||||
Article.boosted_via_additional_articles
|
||||
.includes(:user)
|
||||
.limited_columns_internal_select
|
||||
.order(published_at: :desc)
|
||||
.page(params[:page])
|
||||
.per(100)
|
||||
end
|
||||
|
||||
def articles_chronological
|
||||
Article.published
|
||||
.includes(user: [:notes])
|
||||
|
|
|
|||
|
|
@ -39,18 +39,6 @@ class ArticleDecorator < ApplicationDecorator
|
|||
end
|
||||
end
|
||||
|
||||
def internal_utm_params(place = "additional_box")
|
||||
org_slug = organization&.slug
|
||||
|
||||
campaign = if boosted_additional_articles
|
||||
"#{org_slug}_boosted"
|
||||
else
|
||||
"regular"
|
||||
end
|
||||
|
||||
"?utm_source=#{place}&utm_medium=internal&utm_campaign=#{campaign}&booster_org=#{org_slug}"
|
||||
end
|
||||
|
||||
def published_at_int
|
||||
published_at.to_i
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ class Article < ApplicationRecord
|
|||
validates :body_markdown, bytesize: { maximum: 800.kilobytes, too_long: "is too long." }
|
||||
validates :body_markdown, length: { minimum: 0, allow_nil: false }
|
||||
validates :body_markdown, uniqueness: { scope: %i[user_id title] }
|
||||
validates :boost_states, presence: true
|
||||
validates :cached_tag_list, length: { maximum: 126 }
|
||||
validates :canonical_url,
|
||||
uniqueness: { allow_nil: true, scope: :published, message: UNIQUE_URL_ERROR },
|
||||
|
|
@ -250,28 +249,20 @@ class Article < ApplicationRecord
|
|||
:video, :user_id, :organization_id, :video_source_url, :video_code,
|
||||
:video_thumbnail_url, :video_closed_caption_track_url,
|
||||
:experience_level_rating, :experience_level_rating_distribution, :cached_user, :cached_organization,
|
||||
:published_at, :crossposted_at, :boost_states, :description, :reading_time, :video_duration_in_seconds,
|
||||
:published_at, :crossposted_at, :description, :reading_time, :video_duration_in_seconds,
|
||||
:last_comment_at)
|
||||
}
|
||||
|
||||
scope :limited_columns_internal_select, lambda {
|
||||
select(:path, :title, :id, :featured, :approved, :published,
|
||||
:comments_count, :public_reactions_count, :cached_tag_list,
|
||||
:main_image, :main_image_background_hex_color, :updated_at, :boost_states,
|
||||
: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)
|
||||
}
|
||||
|
||||
scope :boosted_via_additional_articles, lambda {
|
||||
where("boost_states ->> 'boosted_additional_articles' = 'true'")
|
||||
}
|
||||
|
||||
scope :boosted_via_dev_digest_email, lambda {
|
||||
where("boost_states ->> 'boosted_dev_digest_email' = 'true'")
|
||||
}
|
||||
|
||||
scope :sorting, lambda { |value|
|
||||
value ||= "creation-desc"
|
||||
kind, dir = value.split("-")
|
||||
|
|
@ -308,12 +299,6 @@ class Article < ApplicationRecord
|
|||
|
||||
scope :eager_load_serialized_data, -> { includes(:user, :organization, :tags) }
|
||||
|
||||
store_attributes :boost_states do
|
||||
boosted_additional_articles Boolean, default: false
|
||||
boosted_dev_digest_email Boolean, default: false
|
||||
boosted_additional_tags String, default: ""
|
||||
end
|
||||
|
||||
def self.seo_boostable(tag = nil, time_ago = 18.days.ago)
|
||||
# Time ago sometimes returns this phrase instead of a date
|
||||
time_ago = 5.days.ago if time_ago == "latest"
|
||||
|
|
|
|||
|
|
@ -24,10 +24,8 @@
|
|||
<div>
|
||||
<a href="<%= article.path %>/edit" target="_blank" rel="noopener"><span class="btn btn-sm btn-primary">Edit</span></a>
|
||||
|
||||
<button class="btn btn-sm btn-success" data-action="article#increaseFeaturedNumber">Boost</button>
|
||||
|
||||
<a class="btn btn-sm btn-secondary" href="<%= admin_user_path(article.user_id) %>" target="_blank" rel="noopener">Manage User</a>
|
||||
|
||||
|
||||
<% if decorated_article.pinned? %>
|
||||
<%= link_to(
|
||||
"Unpin Post",
|
||||
|
|
@ -141,9 +139,6 @@
|
|||
<label for="approved-<%= article.id %>">Approved</label>
|
||||
</div>
|
||||
<div class="form-check col">
|
||||
<%= f.check_box :boosted_additional_articles, id: "boosted_additional_articles-#{article.id}" %>
|
||||
<label for="boosted_additional_articles-<%= article.id %>">Boosted</label>
|
||||
</div>
|
||||
<div class="form-check col">
|
||||
<%= check_box_tag :pinned, "1", decorated_article.pinned?,
|
||||
name: "article[pinned]",
|
||||
|
|
@ -160,23 +155,5 @@
|
|||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if article.boosted_dev_digest_email %>
|
||||
<br /><br />
|
||||
<% phrase = "#{article.path}?booster_org=#{article.organization&.slug || 'generic'}" %>
|
||||
<b>BOOSTED IN <%= EmailMessage.where("subject LIKE ?", "%#{phrase}%").where.not(opened_at: nil).size %> EMAILS</b>
|
||||
<br />
|
||||
<b>BOOSTED IN
|
||||
<%= EmailMessage.where("subject LIKE ?", "%#{phrase}%").where.not(opened_at: nil).where("sent_at > ?", 1.week.ago).size %>
|
||||
EMAILS IN THE PAST WEEK</b>
|
||||
<br /><br />
|
||||
<b>BOOSTED IN
|
||||
<%= EmailMessage.where("subject LIKE ?", "%#{phrase}%").where.not(opened_at: nil).where.not(opened_at: nil).size %>
|
||||
OPENED EMAILS</b>
|
||||
<br />
|
||||
<b>BOOSTED IN
|
||||
<%= EmailMessage.where("subject LIKE ?", "%#{phrase}%").where.not(opened_at: nil).where.not(opened_at: nil).where("sent_at > ?", 1.week.ago).size %>
|
||||
OPENED EMAILS IN THE PAST WEEK</b>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@
|
|||
href="<%= admin_articles_path(state: :chronological) %>"
|
||||
class="nav-link <%= "active" if params[:state] == "chronological" %>">Chronological</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a
|
||||
href="<%= admin_articles_path(state: :satellite) %>"
|
||||
class="nav-link <%= "active" if params[:state] == "satellite" %>">Satellite</a>
|
||||
</li>
|
||||
</ul>
|
||||
<% if params[:state] && params[:state].include?("top-") && params[:state] != "top-3" && params[:state] != "top-6" %>
|
||||
<h1 style="color:red">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
class DropBoostStatesFromArticles < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
safety_assured do
|
||||
remove_column :articles, :boost_states, :jsonb
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_08_30_062627) do
|
||||
ActiveRecord::Schema.define(version: 2021_10_07_172232) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "citext"
|
||||
|
|
@ -86,7 +86,6 @@ ActiveRecord::Schema.define(version: 2021_08_30_062627) do
|
|||
t.boolean "archived", default: false
|
||||
t.text "body_html"
|
||||
t.text "body_markdown"
|
||||
t.jsonb "boost_states", default: {}, null: false
|
||||
t.text "cached_organization"
|
||||
t.string "cached_tag_list"
|
||||
t.text "cached_user"
|
||||
|
|
@ -154,7 +153,6 @@ ActiveRecord::Schema.define(version: 2021_08_30_062627) do
|
|||
t.string "video_state"
|
||||
t.string "video_thumbnail_url"
|
||||
t.index "user_id, title, digest(body_markdown, 'sha512'::text)", name: "index_articles_on_user_id_and_title_and_digest_body_markdown", unique: true
|
||||
t.index ["boost_states"], name: "index_articles_on_boost_states", using: :gin
|
||||
t.index ["cached_tag_list"], name: "index_articles_on_cached_tag_list", opclass: :gin_trgm_ops, using: :gin
|
||||
t.index ["canonical_url"], name: "index_articles_on_canonical_url", unique: true, where: "(published IS TRUE)"
|
||||
t.index ["collection_id"], name: "index_articles_on_collection_id"
|
||||
|
|
|
|||
|
|
@ -114,52 +114,6 @@ RSpec.describe ArticleDecorator, type: :decorator do
|
|||
end
|
||||
end
|
||||
|
||||
describe "internal_utm_params" do
|
||||
it "returns utm params for a boosted article" do
|
||||
article.boosted_additional_articles = true
|
||||
|
||||
params = ["utm_medium=internal", "utm_campaign=_boosted", "booster_org="]
|
||||
expected_result = "?utm_source=additional_box&#{params.join('&')}"
|
||||
expect(article.decorate.internal_utm_params).to eq(expected_result)
|
||||
end
|
||||
|
||||
it "returns utm params for a boosted article belonging to an organization" do
|
||||
article.boosted_additional_articles = true
|
||||
article.organization = organization
|
||||
|
||||
slug = organization.slug
|
||||
params = ["utm_medium=internal", "utm_campaign=#{slug}_boosted", "booster_org=#{slug}"]
|
||||
expected_result = "?utm_source=additional_box&#{params.join('&')}"
|
||||
expect(article.decorate.internal_utm_params).to eq(expected_result)
|
||||
end
|
||||
|
||||
it "returns utm params for a regular article" do
|
||||
article.boosted_additional_articles = false
|
||||
|
||||
params = ["utm_medium=internal", "utm_campaign=regular", "booster_org="]
|
||||
expected_result = "?utm_source=additional_box&#{params.join('&')}"
|
||||
expect(article.decorate.internal_utm_params).to eq(expected_result)
|
||||
end
|
||||
|
||||
it "returns utm params for a regular article belonging to an organization" do
|
||||
article.boosted_additional_articles = false
|
||||
article.organization = organization
|
||||
|
||||
slug = organization.slug
|
||||
params = ["utm_medium=internal", "utm_campaign=regular", "booster_org=#{slug}"]
|
||||
expected_result = "?utm_source=additional_box&#{params.join('&')}"
|
||||
expect(article.decorate.internal_utm_params).to eq(expected_result)
|
||||
end
|
||||
|
||||
it "returns utm params for an article in a different place" do
|
||||
article.boosted_additional_articles = false
|
||||
|
||||
params = ["utm_medium=internal", "utm_campaign=regular", "booster_org="]
|
||||
expected_result = "?utm_source=homepage&#{params.join('&')}"
|
||||
expect(article.decorate.internal_utm_params("homepage")).to eq(expected_result)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#published_at_int" do
|
||||
it "returns the publication date as an integer" do
|
||||
expect(article.decorate.published_at_int).to eq(article.published_at.to_i)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ RSpec.describe Article, type: :model do
|
|||
it { is_expected.to validate_length_of(:cached_tag_list).is_at_most(126) }
|
||||
it { is_expected.to validate_length_of(:title).is_at_most(128) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:boost_states) }
|
||||
it { is_expected.to validate_presence_of(:comments_count) }
|
||||
it { is_expected.to validate_presence_of(:positive_reactions_count) }
|
||||
it { is_expected.to validate_presence_of(:previous_public_reactions_count) }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue