From 20a3abd86443365b2b4f8f63b1a1ab32389a29b2 Mon Sep 17 00:00:00 2001 From: Pirate Praveen Date: Wed, 7 Jul 2021 20:54:08 +0530 Subject: [PATCH 1/2] Switch to terser gem from uglifier for JS compression closes #8268 --- Changelog.md | 1 + Gemfile | 2 +- Gemfile.lock | 6 +++--- config/environments/production.rb | 2 +- lib/bookmarklet_renderer.rb | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index cfa307ae3..5b743dc28 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ * Fix html-syntax in some handlebars templates [#8251](https://github.com/diaspora/diaspora/pull/8251) * Remove `chat_enabled` flag from archive export [#8265](https://github.com/diaspora/diaspora/pull/8265) * Change thumbnails in image slideshow to squares [#8275](https://github.com/diaspora/diaspora/pull/8275) +* Replace uglifier with terser for JS compression [#8268](https://github.com/diaspora/diaspora/pull/8268) ## Bug fixes diff --git a/Gemfile b/Gemfile index 23ea1f5f4..395ccf4de 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem "sidekiq-cron", "1.2.0" # Compression -gem "uglifier", "4.2.0" +gem "terser", "1.1.5" # Configuration diff --git a/Gemfile.lock b/Gemfile.lock index 75f599597..5c5639f9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -724,6 +724,8 @@ GEM temple (0.8.2) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) + terser (1.1.5) + execjs (>= 0.3.0, < 3) thor (1.1.0) thread_safe (0.3.6) tilt (2.0.10) @@ -749,8 +751,6 @@ GEM ethon (>= 0.9.0) tzinfo (1.2.9) thread_safe (~> 0.1) - uglifier (4.2.0) - execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext unf_ext (0.0.7.7) @@ -918,13 +918,13 @@ DEPENDENCIES sinon-rails (= 1.15.0) sprockets-rails (= 3.2.2) string-direction (= 1.2.2) + terser (= 1.1.5) timecop (= 0.9.4) toml-rb (= 2.0.1) turbo_dev_assets (= 0.0.2) twitter (= 7.0.0) twitter-text (= 1.14.7) typhoeus (= 1.4.0) - uglifier (= 4.2.0) unicorn (= 6.0.0) unicorn-worker-killer (= 0.4.5) uuid (= 2.3.9) diff --git a/config/environments/production.rb b/config/environments/production.rb index 304613a67..13a91a017 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -27,7 +27,7 @@ Rails.application.configure do config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + config.assets.js_compressor = :terser # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. diff --git a/lib/bookmarklet_renderer.rb b/lib/bookmarklet_renderer.rb index 75b2b51f1..a8e998a73 100644 --- a/lib/bookmarklet_renderer.rb +++ b/lib/bookmarklet_renderer.rb @@ -30,7 +30,7 @@ class BookmarkletRenderer def compile src = File.read(source) - @body = Uglifier.compile(src) + @body = Terser.compile(src) FileUtils.mkdir_p cached_path.dirname File.open(cached_path, "w") {|f| f.write(@body) } end From 8691e650dc726fb929df33409475594111b231da Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Sat, 17 Jul 2021 17:39:20 +0200 Subject: [PATCH 2/2] Person.find_or_fetch_by_identifier never return nil Person.find_or_fetch_by_identifier raises an exception if person is not found localy and not fetchable. It never returns nil. These code changes take care about this behaviour and changes specs and code to behave equally. Also related to #8253 --- app/models/user.rb | 9 +++++++-- app/workers/fetch_webfinger.rb | 4 +++- spec/models/user_spec.rb | 6 +++--- spec/workers/fetch_webfinger_spec.rb | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 14eb4562c..788fe6aba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -442,8 +442,13 @@ class User < ApplicationRecord aq = self.aspects.create(:name => I18n.t('aspects.seed.acquaintances')) if AppConfig.settings.autofollow_on_join? - default_account = Person.find_or_fetch_by_identifier(AppConfig.settings.autofollow_on_join_user) - self.share_with(default_account, aq) if default_account + begin + default_account = Person.find_or_fetch_by_identifier(AppConfig.settings.autofollow_on_join_user) + share_with(default_account, aq) + rescue DiasporaFederation::Discovery::DiscoveryError + logger.warn "Error auto-sharing with #{AppConfig.settings.autofollow_on_join_user} + fix autofollow_on_join_user in configuration." + end end aq end diff --git a/app/workers/fetch_webfinger.rb b/app/workers/fetch_webfinger.rb index d2f00b0dc..dbf4f95e6 100644 --- a/app/workers/fetch_webfinger.rb +++ b/app/workers/fetch_webfinger.rb @@ -12,7 +12,9 @@ module Workers person = Person.find_or_fetch_by_identifier(account) # also, schedule to fetch a few public posts from that person - Diaspora::Fetcher::Public.queue_for(person) unless person.nil? + Diaspora::Fetcher::Public.queue_for(person) + rescue DiasporaFederation::Discovery::DiscoveryError + # Ignored end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f457c9b28..623c87af8 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -811,10 +811,10 @@ describe User, :type => :model do context "with autofollow sharing enabled" do it "should start sharing with autofollow account" do AppConfig.settings.autofollow_on_join = true - AppConfig.settings.autofollow_on_join_user = "one" - - expect(Person).to receive(:find_or_fetch_by_identifier).with("one") + person = FactoryBot.build(:person) + AppConfig.settings.autofollow_on_join_user = person.diaspora_handle + expect(Person).to receive(:find_or_fetch_by_identifier).with(person.diaspora_handle).and_return(person) user.seed_aspects end end diff --git a/spec/workers/fetch_webfinger_spec.rb b/spec/workers/fetch_webfinger_spec.rb index 234c7d215..3ed3e4ffa 100644 --- a/spec/workers/fetch_webfinger_spec.rb +++ b/spec/workers/fetch_webfinger_spec.rb @@ -11,7 +11,7 @@ describe Workers::FetchWebfinger do end it "should webfinger and queue no job to fetch public posts if the person is not found" do - allow(Person).to receive(:find_or_fetch_by_identifier).and_return(nil) + allow(Person).to receive(:find_or_fetch_by_identifier).and_raise DiasporaFederation::Discovery::DiscoveryError expect(Diaspora::Fetcher::Public).not_to receive(:queue_for)