Rremove de-indexing From Accounts With No Comments (#20660)

* remove de-indexing from accounts that have no comments

* add specs for Article#skip_indexing?
This commit is contained in:
Daniel M Brasil 2024-02-21 07:54:02 -03:00 committed by GitHub
parent d8ed35a94e
commit 406e3fec4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 74 additions and 4 deletions

View file

@ -631,11 +631,9 @@ class Article < ApplicationRecord
def skip_indexing?
# should the article be skipped indexed by crawlers?
# true if unpublished, or spammy,
# or low score, not featured, and from a user with no comments
# or low score, and not featured
!published ||
(score < Settings::UserExperience.index_minimum_score &&
user.comments_count < 1 &&
!featured) ||
(score < Settings::UserExperience.index_minimum_score && !featured) ||
published_at.to_i < Settings::UserExperience.index_minimum_date.to_i ||
score < -1
end

View file

@ -1560,4 +1560,76 @@ RSpec.describe Article do
end
end
end
describe "#skip_indexing?" do
context "when the article is unpublished" do
let(:article) { build(:unpublished_article) }
it "returns true" do
expect(article.skip_indexing?).to be true
end
end
context "when the article has score below minimum and is not featured" do
let(:article) { build(:published_article, featured: false, score: 2, published_at: 1.day.ago) }
before do
allow(Settings::UserExperience).to receive_messages(index_minimum_score: 10,
index_minimum_date: 1.week.ago)
end
it "returns true" do
expect(article.skip_indexing?).to be true
end
end
context "when the article has score above or equal to minimum and is not featured" do
let(:article) { build(:published_article, featured: false, score: 10, published_at: 1.day.ago) }
before do
allow(Settings::UserExperience).to receive_messages(index_minimum_score: 10,
index_minimum_date: 1.week.ago)
end
it "returns false" do
expect(article.skip_indexing?).to be false
end
end
context "when the article was published before the minimum date" do
let(:article) { build(:published_article, published_at: 1.week.ago) }
before do
allow(Settings::UserExperience).to receive(:index_minimum_date).and_return(1.day.ago)
end
it "returns true" do
expect(article.skip_indexing?).to be true
end
end
context "when the article was published after the minimum date" do
let(:article) { build(:published_article, published_at: 1.day.ago) }
before do
allow(Settings::UserExperience).to receive(:index_minimum_date).and_return(1.week.ago)
end
it "returns false" do
expect(article.skip_indexing?).to be false
end
end
context "when article score is below -1" do
let(:article) { build(:published_article, score: -2, published_at: 1.day.ago) }
before do
allow(Settings::UserExperience).to receive(:index_minimum_date).and_return(1.week.ago)
end
it "returns true" do
expect(article.skip_indexing?).to be true
end
end
end
end