diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index cee7a979..cc0323e1 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -21,6 +21,10 @@ html { border: 1px #e1e4e8 solid; } +.w-full { + width: 100%; +} + .about-section { display: flex; align-items: center; diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index 465645b8..4048e21d 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -1,7 +1,3 @@ -.user-avatar { - overflow-y: hidden; -} - .timeline .timeline-item { padding-bottom: 0.5em; position: relative; diff --git a/app/controllers/images/calendars_controller.rb b/app/controllers/images/calendars_controller.rb index 879a8b3d..d75e886b 100644 --- a/app/controllers/images/calendars_controller.rb +++ b/app/controllers/images/calendars_controller.rb @@ -1,11 +1,13 @@ class Images::CalendarsController < ApplicationController include UserScoped + before_action :check_deprecated_signature_image + def show if small? redirect_to @user.calendar_image.variant(:small) else - redirect_to @user.calendar_image.variant(:large) + redirect_to @user.calendar_image end end @@ -14,4 +16,10 @@ def show def small? params[:variant] == "small" end + + def check_deprecated_signature_image + return if @user.calendar_image.attached? + + redirect_to @user.signature + end end diff --git a/app/controllers/signatures_controller.rb b/app/controllers/signatures_controller.rb deleted file mode 100644 index 08b0d789..00000000 --- a/app/controllers/signatures_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class SignaturesController < ApplicationController - include UserScoped - - def show - redirect_to @user.signature - end -end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index e21fadec..9c96bd8a 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,3 +1,5 @@ class ApplicationJob < ActiveJob::Base include UniqueJobs + + retry_on(ActiveRecord::StatementInvalid, attempts: 3, wait: :polynomially_longer) end diff --git a/app/jobs/user/periodic_mal_sync_job.rb b/app/jobs/user/periodic_mal_sync_job.rb index 6271986d..97c08845 100644 --- a/app/jobs/user/periodic_mal_sync_job.rb +++ b/app/jobs/user/periodic_mal_sync_job.rb @@ -13,9 +13,10 @@ class User::PeriodicMALSyncJob < ApplicationJob if user.legacy_account? user.schedule_deactivation(reason: error.message) Rails.logger.warn("Scheduled deactivation for user #{user.to_global_id}, reason: #{error}") + else + Rails.logger.error(error) + user.touch(:mal_synced_at) end - - Rails.error.report(error) end rescue_from MAL::Errors::CommunicationError do |exception| diff --git a/app/models/user.rb b/app/models/user.rb index 0c2f00e6..0f473375 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,6 @@ class User < ApplicationRecord include Mergeable include Calendars include CalendarImageable - include Signaturable include Deactivatable include Geolocatable diff --git a/app/models/user/calendar_imageable.rb b/app/models/user/calendar_imageable.rb index 386b07bb..cbb8b824 100644 --- a/app/models/user/calendar_imageable.rb +++ b/app/models/user/calendar_imageable.rb @@ -3,10 +3,11 @@ module User::CalendarImageable included do has_one_attached :calendar_image do |attachable| - attachable.variant :large, resize_to_limit: [1200, 180], preprocessed: true - attachable.variant :small, resize_to_limit: [600, 150], preprocessed: true + attachable.variant :small, resize_to_limit: [600, 150], saver: { quality: 100 }, preprocessed: true end + has_one_attached :signature # Deprecated + after_create_commit :enqueue_calendar_images_generation after_update_commit :enqueue_calendar_images_generation, if: -> { calendar_images.obsolete? } end diff --git a/app/models/user/calendar_images.rb b/app/models/user/calendar_images.rb index 9c090191..0d385c57 100644 --- a/app/models/user/calendar_images.rb +++ b/app/models/user/calendar_images.rb @@ -26,7 +26,7 @@ def obsolete? class GenerateJob < ApplicationJob retry_on(*BrowserSession::RETRYABLE_ERRORS, attempts: 10, wait: :polynomially_longer) - limits_concurrency to: 1, key: :screenshots, duration: 2.hours + limits_concurrency to: 2, key: :screenshots, duration: 2.hours queue_as :screenshots diff --git a/app/models/user/signaturable.rb b/app/models/user/signaturable.rb deleted file mode 100644 index 5a30f07e..00000000 --- a/app/models/user/signaturable.rb +++ /dev/null @@ -1,22 +0,0 @@ -class User - module Signaturable - extend ActiveSupport::Concern - - included do - has_one_attached :signature - - after_create_commit :enqueue_signature_generation - after_update_commit :enqueue_signature_generation, if: -> { signature_image.obsolete? } - end - - def signature_image - SignatureImage.new(self) - end - - private - - def enqueue_signature_generation - signature_image.generate_later - end - end -end diff --git a/app/models/user/signaturable/signature_image.rb b/app/models/user/signaturable/signature_image.rb deleted file mode 100644 index 55f322cf..00000000 --- a/app/models/user/signaturable/signature_image.rb +++ /dev/null @@ -1,82 +0,0 @@ -require "image_processing/vips" - -class User - module Signaturable - class SignatureImage - def initialize(user) - super() - @user = user - end - - def generate - Instrumentation.instrument(title: "#{self.class.name}#generate") do - user.with_time_zone { generate_from_activities } - end - end - - def generate_later - User::Signaturable::SignatureImage::GenerateJob.perform_later(user) - end - - def obsolete? - return true unless user.signature.attached? - return true if user.saved_change_to_checksum? - - user.signature.blob.created_at.in_time_zone.to_date != Time.zone.today - end - - class GenerateJob < ApplicationJob - retry_on(*BrowserSession::RETRYABLE_ERRORS, attempts: 10, wait: :polynomially_longer) - - limits_concurrency to: 1, key: :screenshots, duration: 2.hours - - queue_as :screenshots - - def perform(user) - user.signature_image.generate - end - end - - private - - attr_reader :user - - def generate_from_activities - calendar_html = render_calendar_html - - capture_html_screenshot(calendar_html) - .then { |screenshot| resize_to_mal_max_size(screenshot) } - .then { |screenshot| user.signature.attach(io: screenshot, filename: "#{user.username}.png") } - end - - def render_calendar_html - activities_amount_per_day = user.calendars.current_year.activities_amount_sum_per_day - - ApplicationController.render("users/signature", locals: { activities_amount_per_day: }, layout: nil) - end - - def capture_html_screenshot(html_page) - png_image = nil - - BrowserSession.fetch_page do |page| - page.go_to("data:text/html;base64,#{Base64.strict_encode64(html_page)}") - - png_image = page - .screenshot(selector: ".signature", format: :png, encoding: :binary) - .then { Vips::Image.new_from_buffer(_1, "") } - end - - png_image - end - - def resize_to_mal_max_size(screenshot_file) - Rails.logger.info("Resizing screenshot with libvips") - ImageProcessing::Vips - .source(screenshot_file) - .saver(quality: 100) - .resize_to_limit(600, 150) - .call - end - end - end -end diff --git a/app/views/users/_bb_code.html.erb b/app/views/users/_bb_code.html.erb index af4773cd..03c189a7 100644 --- a/app/views/users/_bb_code.html.erb +++ b/app/views/users/_bb_code.html.erb @@ -1,10 +1,10 @@ -<%# locals: (user:) -%> +<%# locals: (user:, label:, help:, variant: nil) -%> -<% template = "[URL=\"#{user_url(user)}\"][IMG]#{user_signature_url(user)}[/IMG][/URL]" %> +<% template = "[URL=\"#{user_url(user)}\"][IMG]#{user_images_calendar_url(user, variant: variant)}[/IMG][/URL]" %> -
<%= help %>