From 45ebdb72ca1678eb30e6087f61bd019c7ea903f4 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 8 Oct 2022 16:45:40 +0200 Subject: Add support for language preferences for trending statuses and links (#18288) --- db/migrate/20220824233535_create_status_trends.rb | 12 +++++++++++ .../20221006061337_create_preview_card_trends.rb | 11 ++++++++++ db/schema.rb | 25 +++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220824233535_create_status_trends.rb create mode 100644 db/migrate/20221006061337_create_preview_card_trends.rb (limited to 'db') diff --git a/db/migrate/20220824233535_create_status_trends.rb b/db/migrate/20220824233535_create_status_trends.rb new file mode 100644 index 000000000..cea0abf35 --- /dev/null +++ b/db/migrate/20220824233535_create_status_trends.rb @@ -0,0 +1,12 @@ +class CreateStatusTrends < ActiveRecord::Migration[6.1] + def change + create_table :status_trends do |t| + t.references :status, null: false, foreign_key: { on_delete: :cascade }, index: { unique: true } + t.references :account, null: false, foreign_key: { on_delete: :cascade } + t.float :score, null: false, default: 0 + t.integer :rank, null: false, default: 0 + t.boolean :allowed, null: false, default: false + t.string :language + end + end +end diff --git a/db/migrate/20221006061337_create_preview_card_trends.rb b/db/migrate/20221006061337_create_preview_card_trends.rb new file mode 100644 index 000000000..baad9c31c --- /dev/null +++ b/db/migrate/20221006061337_create_preview_card_trends.rb @@ -0,0 +1,11 @@ +class CreatePreviewCardTrends < ActiveRecord::Migration[6.1] + def change + create_table :preview_card_trends do |t| + t.references :preview_card, null: false, foreign_key: { on_delete: :cascade }, index: { unique: true } + t.float :score, null: false, default: 0 + t.integer :rank, null: false, default: 0 + t.boolean :allowed, null: false, default: false + t.string :language + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1a98b22db..2f9058509 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_08_29_192658) do +ActiveRecord::Schema.define(version: 2022_10_06_061337) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -735,6 +735,15 @@ ActiveRecord::Schema.define(version: 2022_08_29_192658) do t.index ["domain"], name: "index_preview_card_providers_on_domain", unique: true end + create_table "preview_card_trends", force: :cascade do |t| + t.bigint "preview_card_id", null: false + t.float "score", default: 0.0, null: false + t.integer "rank", default: 0, null: false + t.boolean "allowed", default: false, null: false + t.string "language" + t.index ["preview_card_id"], name: "index_preview_card_trends_on_preview_card_id", unique: true + end + create_table "preview_cards", force: :cascade do |t| t.string "url", default: "", null: false t.string "title", default: "", null: false @@ -894,6 +903,17 @@ ActiveRecord::Schema.define(version: 2022_08_29_192658) do t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true end + create_table "status_trends", force: :cascade do |t| + t.bigint "status_id", null: false + t.bigint "account_id", null: false + t.float "score", default: 0.0, null: false + t.integer "rank", default: 0, null: false + t.boolean "allowed", default: false, null: false + t.string "language" + t.index ["account_id"], name: "index_status_trends_on_account_id" + t.index ["status_id"], name: "index_status_trends_on_status_id", unique: true + end + create_table "statuses", id: :bigint, default: -> { "timestamp_id('statuses'::text)" }, force: :cascade do |t| t.string "uri" t.text "text", default: "", null: false @@ -1171,6 +1191,7 @@ ActiveRecord::Schema.define(version: 2022_08_29_192658) do add_foreign_key "poll_votes", "polls", on_delete: :cascade add_foreign_key "polls", "accounts", on_delete: :cascade add_foreign_key "polls", "statuses", on_delete: :cascade + add_foreign_key "preview_card_trends", "preview_cards", on_delete: :cascade add_foreign_key "report_notes", "accounts", on_delete: :cascade add_foreign_key "report_notes", "reports", on_delete: :cascade add_foreign_key "reports", "accounts", column: "action_taken_by_account_id", name: "fk_bca45b75fd", on_delete: :nullify @@ -1185,6 +1206,8 @@ ActiveRecord::Schema.define(version: 2022_08_29_192658) do add_foreign_key "status_pins", "accounts", name: "fk_d4cb435b62", on_delete: :cascade add_foreign_key "status_pins", "statuses", on_delete: :cascade add_foreign_key "status_stats", "statuses", on_delete: :cascade + add_foreign_key "status_trends", "accounts", on_delete: :cascade + add_foreign_key "status_trends", "statuses", on_delete: :cascade add_foreign_key "statuses", "accounts", column: "in_reply_to_account_id", name: "fk_c7fa917661", on_delete: :nullify add_foreign_key "statuses", "accounts", name: "fk_9bda1543f7", on_delete: :cascade add_foreign_key "statuses", "statuses", column: "in_reply_to_id", on_delete: :nullify -- cgit From 5f79200a5e39a5bf243068d040def2af35f211fc Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Sun, 9 Oct 2022 22:33:38 +0000 Subject: Remove/update old "tootsuite" references, except those needed for Docker (#19327) --- chart/values.yaml | 4 ++-- db/migrate/20170918125918_ids_to_bigints.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'db') diff --git a/chart/values.yaml b/chart/values.yaml index 4b18a9dfa..48554412f 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -24,7 +24,7 @@ mastodon: removeMedia: enabled: true schedule: "0 0 * * 0" - # available locales: https://github.com/tootsuite/mastodon/blob/master/config/application.rb#L43 + # available locales: https://github.com/mastodon/mastodon/blob/main/config/application.rb#L71 locale: en local_domain: mastodon.local # Use of WEB_DOMAIN requires careful consideration: https://docs.joinmastodon.org/admin/config/#federation @@ -261,7 +261,7 @@ externalAuth: # search: "., -" # replace: _ -# https://github.com/tootsuite/mastodon/blob/master/Dockerfile#L88 +# https://github.com/mastodon/mastodon/blob/main/Dockerfile#L75 # # if you manually change the UID/GID environment variables, ensure these values # match: diff --git a/db/migrate/20170918125918_ids_to_bigints.rb b/db/migrate/20170918125918_ids_to_bigints.rb index bcb2e9eca..bf875e4e5 100644 --- a/db/migrate/20170918125918_ids_to_bigints.rb +++ b/db/migrate/20170918125918_ids_to_bigints.rb @@ -80,7 +80,7 @@ class IdsToBigints < ActiveRecord::Migration[5.1] say 'This migration has some sections that can be safely interrupted' say 'and restarted later, and will tell you when those are occurring.' say '' - say 'For more information, see https://github.com/tootsuite/mastodon/pull/5088' + say 'For more information, see https://github.com/mastodon/mastodon/pull/5088' 10.downto(1) do |i| say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true -- cgit From b04633a9614609f18b39ba0f0015df301a04ab64 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 13 Oct 2022 11:29:19 +0200 Subject: Add image processing and generate blurhash for server thumbnail (#19348) Remove separate server hero setting --- app/models/form/admin_settings.rb | 2 -- app/models/site_upload.rb | 27 +++++++++++++++++++++- app/presenters/instance_presenter.rb | 4 ---- app/serializers/rest/instance_serializer.rb | 15 +++++++++++- app/serializers/rest/v1/instance_serializer.rb | 2 +- app/views/admin/settings/edit.html.haml | 2 -- app/views/application/_sidebar.html.haml | 2 +- app/views/shared/_og.html.haml | 2 +- config/locales/en.yml | 3 --- .../20221012181003_add_blurhash_to_site_uploads.rb | 5 ++++ db/schema.rb | 3 ++- spec/presenters/instance_presenter_spec.rb | 7 ------ 12 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20221012181003_add_blurhash_to_site_uploads.rb (limited to 'db') diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 7bd9e3743..b6bb3d795 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -22,7 +22,6 @@ class Form::AdminSettings custom_css profile_directory thumbnail - hero mascot trends trendable_by_default @@ -49,7 +48,6 @@ class Form::AdminSettings UPLOAD_KEYS = %i( thumbnail - hero mascot ).freeze diff --git a/app/models/site_upload.rb b/app/models/site_upload.rb index cf10b30fc..d3b81d4d5 100644 --- a/app/models/site_upload.rb +++ b/app/models/site_upload.rb @@ -12,10 +12,35 @@ # meta :json # created_at :datetime not null # updated_at :datetime not null +# blurhash :string # class SiteUpload < ApplicationRecord - has_attached_file :file + include Attachmentable + + STYLES = { + thumbnail: { + '@1x': { + format: 'png', + geometry: '1200x630#', + file_geometry_parser: FastGeometryParser, + blurhash: { + x_comp: 4, + y_comp: 4, + }.freeze, + }, + + '@2x': { + format: 'png', + geometry: '2400x1260#', + file_geometry_parser: FastGeometryParser, + }.freeze, + }.freeze, + + mascot: {}.freeze, + }.freeze + + has_attached_file :file, styles: ->(file) { STYLES[file.instance.var.to_sym] }, convert_options: { all: '-coalesce -strip' }, processors: [:lazy_thumbnail, :blurhash_transcoder, :type_corrector] validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/ validates :file, presence: true diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index c461ac55f..43594a280 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -84,10 +84,6 @@ class InstancePresenter < ActiveModelSerializers::Model @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') } end - def hero - @hero ||= Rails.cache.fetch('site_uploads/hero') { SiteUpload.find_by(var: 'hero') } - end - def mascot @mascot ||= Rails.cache.fetch('site_uploads/mascot') { SiteUpload.find_by(var: 'mascot') } end diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index f4ea49427..dfa8ce40a 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -17,7 +17,20 @@ class REST::InstanceSerializer < ActiveModel::Serializer has_many :rules, serializer: REST::RuleSerializer def thumbnail - object.thumbnail ? full_asset_url(object.thumbnail.file.url) : full_pack_url('media/images/preview.png') + if object.thumbnail + { + url: full_asset_url(object.thumbnail.file.url(:'@1x')), + blurhash: object.thumbnail.blurhash, + versions: { + '@1x': full_asset_url(object.thumbnail.file.url(:'@1x')), + '@2x': full_asset_url(object.thumbnail.file.url(:'@2x')), + }, + } + else + { + url: full_pack_url('media/images/preview.png'), + } + end end def usage diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index 47fa086fc..872175451 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -33,7 +33,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer end def thumbnail - instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.png') + instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url(:'@1x')) : full_pack_url('media/images/preview.png') end def stats diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index 79f73a60f..15b1a2498 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -34,8 +34,6 @@ .fields-row .fields-row__column.fields-row__column-6.fields-group = f.input :thumbnail, as: :file, wrapper: :with_block_label, label: t('admin.settings.thumbnail.title'), hint: site_upload_delete_hint(t('admin.settings.thumbnail.desc_html'), :thumbnail) - .fields-row__column.fields-row__column-6.fields-group - = f.input :hero, as: :file, wrapper: :with_block_label, label: t('admin.settings.hero.title'), hint: site_upload_delete_hint(t('admin.settings.hero.desc_html'), :hero) .fields-row .fields-row__column.fields-row__column-6.fields-group diff --git a/app/views/application/_sidebar.html.haml b/app/views/application/_sidebar.html.haml index eb2813dd0..6d18668b0 100644 --- a/app/views/application/_sidebar.html.haml +++ b/app/views/application/_sidebar.html.haml @@ -1,6 +1,6 @@ .hero-widget .hero-widget__img - = image_tag @instance_presenter.hero&.file&.url || @instance_presenter.thumbnail&.file&.url || asset_pack_path('media/images/preview.png'), alt: @instance_presenter.title + = image_tag @instance_presenter.thumbnail&.file&.url(:'@1x') || asset_pack_path('media/images/preview.png'), alt: @instance_presenter.title .hero-widget__text %p= @instance_presenter.description.html_safe.presence || t('about.about_mastodon_html') diff --git a/app/views/shared/_og.html.haml b/app/views/shared/_og.html.haml index b54ab2429..2941b566e 100644 --- a/app/views/shared/_og.html.haml +++ b/app/views/shared/_og.html.haml @@ -8,7 +8,7 @@ = opengraph 'og:type', 'website' = opengraph 'og:title', @instance_presenter.title = opengraph 'og:description', description -= opengraph 'og:image', full_asset_url(thumbnail&.file&.url || asset_pack_path('media/images/preview.png', protocol: :request)) += opengraph 'og:image', full_asset_url(thumbnail&.file&.url(:'@1x') || asset_pack_path('media/images/preview.png', protocol: :request)) = opengraph 'og:image:width', thumbnail ? thumbnail.meta['width'] : '1200' = opengraph 'og:image:height', thumbnail ? thumbnail.meta['height'] : '630' = opengraph 'twitter:card', 'summary_large_image' diff --git a/config/locales/en.yml b/config/locales/en.yml index bd913a5ca..8a70bd8ca 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -735,9 +735,6 @@ en: users: To logged-in local users domain_blocks_rationale: title: Show rationale - hero: - desc_html: Displayed on the frontpage. At least 600x100px recommended. When not set, falls back to server thumbnail - title: Hero image mascot: desc_html: Displayed on multiple pages. At least 293×205px recommended. When not set, falls back to default mascot title: Mascot image diff --git a/db/migrate/20221012181003_add_blurhash_to_site_uploads.rb b/db/migrate/20221012181003_add_blurhash_to_site_uploads.rb new file mode 100644 index 000000000..e1c87712b --- /dev/null +++ b/db/migrate/20221012181003_add_blurhash_to_site_uploads.rb @@ -0,0 +1,5 @@ +class AddBlurhashToSiteUploads < ActiveRecord::Migration[6.1] + def change + add_column :site_uploads, :blurhash, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 2f9058509..3972f777a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_10_06_061337) do +ActiveRecord::Schema.define(version: 2022_10_12_181003) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -866,6 +866,7 @@ ActiveRecord::Schema.define(version: 2022_10_06_061337) do t.json "meta" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "blurhash" t.index ["var"], name: "index_site_uploads_on_var", unique: true end diff --git a/spec/presenters/instance_presenter_spec.rb b/spec/presenters/instance_presenter_spec.rb index a0a8628e8..659c2cc2f 100644 --- a/spec/presenters/instance_presenter_spec.rb +++ b/spec/presenters/instance_presenter_spec.rb @@ -99,13 +99,6 @@ describe InstancePresenter do end end - describe '#hero' do - it 'returns SiteUpload' do - hero = Fabricate(:site_upload, var: 'hero') - expect(instance_presenter.hero).to eq(hero) - end - end - describe '#mascot' do it 'returns SiteUpload' do mascot = Fabricate(:site_upload, var: 'mascot') -- cgit From 53e86747e49dea5e4314bc3fedef4d69ba8f338e Mon Sep 17 00:00:00 2001 From: Takeshi Umeda Date: Sat, 22 Oct 2022 21:30:59 +0900 Subject: Fix duplicate featured tags (#19403) * Fix duplicate featured tags * Add unique tag name validator * Fix error message --- app/models/featured_tag.rb | 1 + ...dd_index_featured_tags_on_account_id_and_tag_id.rb | 19 +++++++++++++++++++ db/schema.rb | 4 ++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20221021055441_add_index_featured_tags_on_account_id_and_tag_id.rb (limited to 'db') diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index 4a8d7224a..ec234a6fd 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -60,5 +60,6 @@ class FeaturedTag < ApplicationRecord def validate_tag_name errors.add(:name, :blank) if @name.blank? errors.add(:name, :invalid) unless @name.match?(/\A(#{Tag::HASHTAG_NAME_RE})\z/i) + errors.add(:name, :taken) if FeaturedTag.by_name(@name).where(account_id: account_id).exists? end end diff --git a/db/migrate/20221021055441_add_index_featured_tags_on_account_id_and_tag_id.rb b/db/migrate/20221021055441_add_index_featured_tags_on_account_id_and_tag_id.rb new file mode 100644 index 000000000..74d7673f7 --- /dev/null +++ b/db/migrate/20221021055441_add_index_featured_tags_on_account_id_and_tag_id.rb @@ -0,0 +1,19 @@ +class AddIndexFeaturedTagsOnAccountIdAndTagId < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def up + duplicates = FeaturedTag.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM featured_tags GROUP BY account_id, tag_id HAVING count(*) > 1').to_ary + + duplicates.each do |row| + FeaturedTag.where(id: row['ids'].split(',')[0...-1]).destroy_all + end + + add_index :featured_tags, [:account_id, :tag_id], unique: true, algorithm: :concurrently + remove_index :featured_tags, [:account_id], algorithm: :concurrently + end + + def down + add_index :featured_tags, [:account_id], algorithm: :concurrently + remove_index :featured_tags, [:account_id, :tag_id], unique: true, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 3972f777a..ed00d9e74 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_10_12_181003) do +ActiveRecord::Schema.define(version: 2022_10_21_055441) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -442,7 +442,7 @@ ActiveRecord::Schema.define(version: 2022_10_12_181003) do t.datetime "last_status_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["account_id"], name: "index_featured_tags_on_account_id" + t.index ["account_id", "tag_id"], name: "index_featured_tags_on_account_id_and_tag_id", unique: true t.index ["tag_id"], name: "index_featured_tags_on_tag_id" end -- cgit From 487d81fb92350974e20ee220553a10b5229f0880 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 25 Oct 2022 21:43:44 +0200 Subject: Fix IP blocks not having a unique index (#19456) --- app/controllers/admin/ip_blocks_controller.rb | 2 +- app/models/ip_block.rb | 1 + db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb | 17 +++++++++++++++++ db/schema.rb | 3 ++- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb (limited to 'db') diff --git a/app/controllers/admin/ip_blocks_controller.rb b/app/controllers/admin/ip_blocks_controller.rb index a87520f4e..1bd7ec805 100644 --- a/app/controllers/admin/ip_blocks_controller.rb +++ b/app/controllers/admin/ip_blocks_controller.rb @@ -5,7 +5,7 @@ module Admin def index authorize :ip_block, :index? - @ip_blocks = IpBlock.page(params[:page]) + @ip_blocks = IpBlock.order(ip: :asc).page(params[:page]) @form = Form::IpBlockBatch.new end diff --git a/app/models/ip_block.rb b/app/models/ip_block.rb index 8666f4248..31343f0e1 100644 --- a/app/models/ip_block.rb +++ b/app/models/ip_block.rb @@ -25,6 +25,7 @@ class IpBlock < ApplicationRecord } validates :ip, :severity, presence: true + validates :ip, uniqueness: true after_commit :reset_cache diff --git a/db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb b/db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb new file mode 100644 index 000000000..0221369b7 --- /dev/null +++ b/db/migrate/20221025171544_add_index_ip_blocks_on_ip.rb @@ -0,0 +1,17 @@ +class AddIndexIpBlocksOnIp < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def up + duplicates = IpBlock.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM ip_blocks GROUP BY ip HAVING count(*) > 1').to_ary + + duplicates.each do |row| + IpBlock.where(id: row['ids'].split(',')[0...-1]).destroy_all + end + + add_index :ip_blocks, :ip, unique: true, algorithm: :concurrently + end + + def down + remove_index :ip_blocks, :ip, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index ed00d9e74..d7e40b133 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_10_21_055441) do +ActiveRecord::Schema.define(version: 2022_10_25_171544) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -521,6 +521,7 @@ ActiveRecord::Schema.define(version: 2022_10_21_055441) do t.inet "ip", default: "0.0.0.0", null: false t.integer "severity", default: 0, null: false t.text "comment", default: "", null: false + t.index ["ip"], name: "index_ip_blocks_on_ip", unique: true end create_table "list_accounts", force: :cascade do |t| -- cgit