diff --git a/Gemfile b/Gemfile index 4cad473bd..9b0512ad6 100644 --- a/Gemfile +++ b/Gemfile @@ -57,7 +57,6 @@ gem "kaminari", "~> 1.2" # A Scope & Engine based, clean, powerful, customizable gem "katex", "~> 0.6.0" # This rubygem enables you to render TeX math to HTML using KaTeX. It uses ExecJS under the hood gem "liquid", "~> 4.0" # A secure, non-evaling end user template engine with aesthetic markup gem "mini_racer", "~> 0.3.1" # Minimal embedded v8 -# gem "miro", "~> 0.4" # Extract colors from image gem "nokogiri", "~> 1.10" # HTML, XML, SAX, and Reader parser gem "octokit", "~> 4.19" # Simple wrapper for the GitHub API gem "oj", "~> 3.10" # JSON parser and object serializer diff --git a/app/labor/color_from_image.rb b/app/labor/color_from_image.rb deleted file mode 100644 index f3de868e7..000000000 --- a/app/labor/color_from_image.rb +++ /dev/null @@ -1,17 +0,0 @@ -class ColorFromImage - def initialize(url) - @url = url - end - - def main - "#dddddd" - # get_hex - rescue StandardError - "#dddddd" - end - - def get_hex - # colors = Miro::DominantColors.new @url - HexComparer.new(colors.to_hex).biggest # Always take the biggest hex (aka lightest color) - end -end diff --git a/app/models/article.rb b/app/models/article.rb index 82ef68776..a22573e04 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -100,7 +100,7 @@ class Article < ApplicationRecord after_update_commit :update_notifications, if: proc { |article| article.notifications.any? && !article.saved_changes.empty? } - after_commit :async_score_calc, :update_main_image_background_hex, :touch_collection, on: %i[create update] + after_commit :async_score_calc, :touch_collection, on: %i[create update] after_commit :index_to_elasticsearch, on: %i[create update] after_commit :remove_from_elasticsearch, on: [:destroy] @@ -436,13 +436,6 @@ class Article < ApplicationRecord self.tag_list = tag_list.map { |tag| Tag.find_preferred_alias_for(tag) } end - def update_main_image_background_hex - return unless saved_changes.key?("main_image") - return if main_image.blank? || main_image_background_hex_color != "#dddddd" - - Articles::UpdateMainImageBackgroundHexWorker.perform_async(id) - end - def detect_human_language return if language.present? diff --git a/app/workers/articles/update_main_image_background_hex_worker.rb b/app/workers/articles/update_main_image_background_hex_worker.rb deleted file mode 100644 index 1d8a2e0a8..000000000 --- a/app/workers/articles/update_main_image_background_hex_worker.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Articles - class UpdateMainImageBackgroundHexWorker - include Sidekiq::Worker - - sidekiq_options queue: :high_priority, retry: 10, lock: :until_executing - - def perform(article_id) - article = Article.find_by(id: article_id) - - return unless article - - article.update_column(:main_image_background_hex_color, ColorFromImage.new(article.main_image).main) - end - end -end diff --git a/spec/labor/color_from_image_spec.rb b/spec/labor/color_from_image_spec.rb deleted file mode 100644 index c8ddc5269..000000000 --- a/spec/labor/color_from_image_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "rails_helper" - -RSpec.describe ColorFromImage, type: :labor do - it "returns a color" do - color = described_class.new(File.expand_path("spec/fixtures/files/image_gps_data.jpg")).main - - expected_regexp = /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/ - expect(color).to match(expected_regexp) - end -end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 94e4586b3..01350a4a4 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -759,37 +759,6 @@ RSpec.describe Article, type: :model do end end - describe "main image background color" do - let(:article) { build(:article, user: user) } - - it "enqueues a job to update the main image background if #dddddd" do - article.main_image_background_hex_color = "#dddddd" - allow(article).to receive(:update_main_image_background_hex).and_call_original - sidekiq_assert_enqueued_with(job: Articles::UpdateMainImageBackgroundHexWorker) do - article.save - end - expect(article).to have_received(:update_main_image_background_hex) - end - - it "does not enqueue a job to update the main image background if not #dddddd" do - article.main_image_background_hex_color = "#fff000" - allow(article).to receive(:update_main_image_background_hex).and_call_original - sidekiq_assert_no_enqueued_jobs(only: Articles::UpdateMainImageBackgroundHexWorker) do - article.save - end - expect(article).to have_received(:update_main_image_background_hex) - end - - it "does not enqueue a job if main_image has not changed" do - article.save - allow(article).to receive(:update_main_image_background_hex).and_call_original - sidekiq_assert_no_enqueued_jobs(only: Articles::UpdateMainImageBackgroundHexWorker) do - article.save - end - expect(article).to have_received(:update_main_image_background_hex) - end - end - describe "spam" do before do allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id) diff --git a/spec/workers/articles/update_main_image_background_hex_worker_spec.rb b/spec/workers/articles/update_main_image_background_hex_worker_spec.rb deleted file mode 100644 index ef4da4088..000000000 --- a/spec/workers/articles/update_main_image_background_hex_worker_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "rails_helper" - -RSpec.describe Articles::UpdateMainImageBackgroundHexWorker, type: :job do - subject(:worker) { described_class.new } - - describe "#perform" do - context "with article" do - let(:article) { create(:article) } - - it "updates articles main image background hex" do - color_from_image = double - allow(color_from_image).to receive(:main).and_return("#eee") - allow(ColorFromImage).to receive(:new).and_return(color_from_image) - - worker.perform(article.id) - - expect(article.reload.main_image_background_hex_color).to eql("#eee") - end - end - - context "without article" do - it "does not error" do - expect { worker.perform(nil) }.not_to raise_error - end - end - end -end