diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/chewy/accounts_index.rb | 24 | ||||
-rw-r--r-- | app/chewy/statuses_index.rb | 48 | ||||
-rw-r--r-- | app/chewy/tags_index.rb | 16 | ||||
-rw-r--r-- | app/javascript/flavours/glitch/styles/admin.scss | 1 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/admin.scss | 1 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/emoji_picker.scss | 2 | ||||
-rw-r--r-- | app/lib/link_details_extractor.rb | 4 | ||||
-rw-r--r-- | app/lib/webfinger.rb | 4 | ||||
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/account_stat.rb | 2 | ||||
-rw-r--r-- | app/models/bookmark.rb | 2 | ||||
-rw-r--r-- | app/models/favourite.rb | 2 | ||||
-rw-r--r-- | app/models/status.rb | 2 | ||||
-rw-r--r-- | app/models/tag.rb | 2 | ||||
-rw-r--r-- | app/services/batched_remove_status_service.rb | 2 | ||||
-rw-r--r-- | app/services/delete_account_service.rb | 4 |
16 files changed, 62 insertions, 56 deletions
diff --git a/app/chewy/accounts_index.rb b/app/chewy/accounts_index.rb index b814e009e..6f9ea76e9 100644 --- a/app/chewy/accounts_index.rb +++ b/app/chewy/accounts_index.rb @@ -23,21 +23,21 @@ class AccountsIndex < Chewy::Index }, } - define_type ::Account.searchable.includes(:account_stat), delete_if: ->(account) { account.destroyed? || !account.searchable? } do - root date_detection: false do - field :id, type: 'long' + index_scope ::Account.searchable.includes(:account_stat), delete_if: ->(account) { account.destroyed? || !account.searchable? } - field :display_name, type: 'text', analyzer: 'content' do - field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' - end + root date_detection: false do + field :id, type: 'long' - field :acct, type: 'text', analyzer: 'content', value: ->(account) { [account.username, account.domain].compact.join('@') } do - field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' - end + field :display_name, type: 'text', analyzer: 'content' do + field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' + end - field :following_count, type: 'long', value: ->(account) { account.following.local.count } - field :followers_count, type: 'long', value: ->(account) { account.followers.local.count } - field :last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at } + field :acct, type: 'text', analyzer: 'content', value: ->(account) { [account.username, account.domain].compact.join('@') } do + field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' end + + field :following_count, type: 'long', value: ->(account) { account.following.local.count } + field :followers_count, type: 'long', value: ->(account) { account.followers.local.count } + field :last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at } end end diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index 47cb856ea..1903c2ea3 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -31,36 +31,36 @@ class StatusesIndex < Chewy::Index }, } - define_type ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll) do - crutch :mentions do |collection| - data = ::Mention.where(status_id: collection.map(&:id)).where(account: Account.local, silent: false).pluck(:status_id, :account_id) - data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } - end + index_scope ::Status.unscoped.kept.without_reblogs.includes(:media_attachments, :preloadable_poll) - crutch :favourites do |collection| - data = ::Favourite.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id) - data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } - end + crutch :mentions do |collection| + data = ::Mention.where(status_id: collection.map(&:id)).where(account: Account.local, silent: false).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end - crutch :reblogs do |collection| - data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id) - data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } - end + crutch :favourites do |collection| + data = ::Favourite.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end - crutch :bookmarks do |collection| - data = ::Bookmark.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id) - data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } - end + crutch :reblogs do |collection| + data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end - root date_detection: false do - field :id, type: 'long' - field :account_id, type: 'long' + crutch :bookmarks do |collection| + data = ::Bookmark.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end - field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do - field :stemmed, type: 'text', analyzer: 'content' - end + root date_detection: false do + field :id, type: 'long' + field :account_id, type: 'long' - field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } + field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do + field :stemmed, type: 'text', analyzer: 'content' end + + field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } end end diff --git a/app/chewy/tags_index.rb b/app/chewy/tags_index.rb index 300fc128f..f811a8d67 100644 --- a/app/chewy/tags_index.rb +++ b/app/chewy/tags_index.rb @@ -23,15 +23,15 @@ class TagsIndex < Chewy::Index }, } - define_type ::Tag.listable, delete_if: ->(tag) { tag.destroyed? || !tag.listable? } do - root date_detection: false do - field :name, type: 'text', analyzer: 'content' do - field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' - end + index_scope ::Tag.listable, delete_if: ->(tag) { tag.destroyed? || !tag.listable? } - field :reviewed, type: 'boolean', value: ->(tag) { tag.reviewed? } - field :usage, type: 'long', value: ->(tag) { tag.history.reduce(0) { |total, day| total + day[:accounts].to_i } } - field :last_status_at, type: 'date', value: ->(tag) { tag.last_status_at || tag.created_at } + root date_detection: false do + field :name, type: 'text', analyzer: 'content' do + field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' end + + field :reviewed, type: 'boolean', value: ->(tag) { tag.reviewed? } + field :usage, type: 'long', value: ->(tag) { tag.history.reduce(0) { |total, day| total + day[:accounts].to_i } } + field :last_status_at, type: 'date', value: ->(tag) { tag.last_status_at || tag.created_at } end end diff --git a/app/javascript/flavours/glitch/styles/admin.scss b/app/javascript/flavours/glitch/styles/admin.scss index bfb09aa0a..8fd556c73 100644 --- a/app/javascript/flavours/glitch/styles/admin.scss +++ b/app/javascript/flavours/glitch/styles/admin.scss @@ -847,6 +847,7 @@ a.name-tag, padding: 0 5px; margin-bottom: 10px; flex: 1 0 50%; + max-width: 100%; } .account__header__fields, diff --git a/app/javascript/styles/mastodon/admin.scss b/app/javascript/styles/mastodon/admin.scss index bfb09aa0a..8fd556c73 100644 --- a/app/javascript/styles/mastodon/admin.scss +++ b/app/javascript/styles/mastodon/admin.scss @@ -847,6 +847,7 @@ a.name-tag, padding: 0 5px; margin-bottom: 10px; flex: 1 0 50%; + max-width: 100%; } .account__header__fields, diff --git a/app/javascript/styles/mastodon/emoji_picker.scss b/app/javascript/styles/mastodon/emoji_picker.scss index adddd4533..e73057465 100644 --- a/app/javascript/styles/mastodon/emoji_picker.scss +++ b/app/javascript/styles/mastodon/emoji_picker.scss @@ -169,7 +169,7 @@ } &:hover::before { - z-index: 0; + z-index: -1; content: ""; position: absolute; top: 0; diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index 3876173e0..8b38e8d0c 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -59,7 +59,7 @@ class LinkDetailsExtractor end def json - @json ||= Oj.load(@data) + @json ||= first_of_value(Oj.load(@data)) end end @@ -178,6 +178,8 @@ class LinkDetailsExtractor @structured_data ||= begin json_ld = document.xpath('//script[@type="application/ld+json"]').map(&:content).first json_ld.present? ? StructuredData.new(json_ld) : nil + rescue Oj::ParseError + nil end end diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb index e0e022cea..1ffb5b4bf 100644 --- a/app/lib/webfinger.rb +++ b/app/lib/webfinger.rb @@ -46,7 +46,9 @@ class Webfinger def body_from_webfinger(url = standard_url, use_fallback = true) webfinger_request(url).perform do |res| if res.code == 200 - res.body_with_limit + body = res.body_with_limit + raise Webfinger::Error, "Request for #{@uri} returned empty response" if body.empty? + body elsif res.code == 404 && use_fallback body_from_host_meta elsif res.code == 410 diff --git a/app/models/account.rb b/app/models/account.rb index d6300a13f..e0e916eb2 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -147,7 +147,7 @@ class Account < ApplicationRecord delegate :chosen_languages, to: :user, prefix: false, allow_nil: true - update_index('accounts#account', :self) + update_index('accounts', :self) def local? domain.nil? diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index e702fa4a4..b49827267 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -19,5 +19,5 @@ class AccountStat < ApplicationRecord belongs_to :account, inverse_of: :account_stat - update_index('accounts#account', :account) + update_index('accounts', :account) end diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index f21ea714c..6334ef0df 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -13,7 +13,7 @@ class Bookmark < ApplicationRecord include Paginable - update_index('statuses#status', :status) if Chewy.enabled? + update_index('statuses', :status) if Chewy.enabled? belongs_to :account, inverse_of: :bookmarks belongs_to :status, inverse_of: :bookmarks diff --git a/app/models/favourite.rb b/app/models/favourite.rb index ca8bce146..2f355739a 100644 --- a/app/models/favourite.rb +++ b/app/models/favourite.rb @@ -13,7 +13,7 @@ class Favourite < ApplicationRecord include Paginable - update_index('statuses#status', :status) + update_index('statuses', :status) belongs_to :account, inverse_of: :favourites belongs_to :status, inverse_of: :favourites diff --git a/app/models/status.rb b/app/models/status.rb index 3a1323849..ef9e6d817 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -45,7 +45,7 @@ class Status < ApplicationRecord # will be based on current time instead of `created_at` attr_accessor :override_timestamps - update_index('statuses#status', :proper) + update_index('statuses', :proper) enum visibility: [:public, :unlisted, :private, :direct, :limited], _suffix: :visibility diff --git a/app/models/tag.rb b/app/models/tag.rb index 735c30608..dcce28391 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -39,7 +39,7 @@ class Tag < ApplicationRecord scope :recently_used, ->(account) { joins(:statuses).where(statuses: { id: account.statuses.select(:id).limit(1000) }).group(:id).order(Arel.sql('count(*) desc')) } scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index - update_index('tags#tag', :self) + update_index('tags', :self) def to_param name diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index 363aa5ccf..2b649ee22 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -32,7 +32,7 @@ class BatchedRemoveStatusService < BaseService # Since we skipped all callbacks, we also need to manually # deindex the statuses - Chewy.strategy.current.update(StatusesIndex::Status, statuses_and_reblogs) if Chewy.enabled? + Chewy.strategy.current.update(StatusesIndex, statuses_and_reblogs) if Chewy.enabled? return if options[:skip_side_effects] diff --git a/app/services/delete_account_service.rb b/app/services/delete_account_service.rb index d8270498a..ac571d7e2 100644 --- a/app/services/delete_account_service.rb +++ b/app/services/delete_account_service.rb @@ -189,7 +189,7 @@ class DeleteAccountService < BaseService @account.favourites.in_batches do |favourites| ids = favourites.pluck(:status_id) StatusStat.where(status_id: ids).update_all('favourites_count = GREATEST(0, favourites_count - 1)') - Chewy.strategy.current.update(StatusesIndex::Status, ids) if Chewy.enabled? + Chewy.strategy.current.update(StatusesIndex, ids) if Chewy.enabled? Rails.cache.delete_multi(ids.map { |id| "statuses/#{id}" }) favourites.delete_all end @@ -197,7 +197,7 @@ class DeleteAccountService < BaseService def purge_bookmarks! @account.bookmarks.in_batches do |bookmarks| - Chewy.strategy.current.update(StatusesIndex::Status, bookmarks.pluck(:status_id)) if Chewy.enabled? + Chewy.strategy.current.update(StatusesIndex, bookmarks.pluck(:status_id)) if Chewy.enabled? bookmarks.delete_all end end |