Skip to content

Commit

Permalink
Merge pull request #707 from kmycode/upstream-20240409
Browse files Browse the repository at this point in the history
Upstream 20240409
  • Loading branch information
kmycode authored Apr 9, 2024
2 parents f87d30a + 52c5784 commit 6cf0f5b
Show file tree
Hide file tree
Showing 34 changed files with 186 additions and 159 deletions.
22 changes: 7 additions & 15 deletions app/controllers/concerns/cache_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,19 @@ def render_with_cache(**options)
end
end

# TODO: Rename this method, as it does not perform any caching anymore.
def cache_collection(raw, klass)
return raw unless klass.respond_to?(:with_includes)
return raw unless klass.respond_to?(:preload_cacheable_associations)

raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
return [] if raw.empty?
records = raw.to_a

cached_keys_with_value = Rails.cache.read_multi(*raw).transform_keys(&:id)
klass.preload_cacheable_associations(records)

uncached_ids = raw.map(&:id) - cached_keys_with_value.keys

klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!)

unless uncached_ids.empty?
uncached = klass.where(id: uncached_ids).with_includes.index_by(&:id)
Rails.cache.write_multi(uncached.values.to_h { |i| [i, i] })
end

raw.filter_map { |item| cached_keys_with_value[item.id] || uncached[item.id] }
records
end

# TODO: Rename this method, as it does not perform any caching anymore.
def cache_collection_paginated_by_id(raw, klass, limit, options)
cache_collection raw.cache_ids.to_a_paginated_by_id(limit, options), klass
cache_collection raw.to_a_paginated_by_id(limit, options), klass
end
end
2 changes: 1 addition & 1 deletion app/javascript/mastodon/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Rails from '@rails/ujs';
import 'font-awesome/css/font-awesome.css';

export function start() {
require.context('../images/', true);
require.context('../images/', true, /\.(jpg|png|svg)$/);

try {
Rails.start();
Expand Down
18 changes: 18 additions & 0 deletions app/javascript/mastodon/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
"block_modal.remote_users_caveat": "Do t’i kërkojmë shërbyesit {domain} të respektojë vendimin tuaj. Por, pajtimi s’është i garantuar, ngaqë disa shërbyes mund t’i trajtojnë ndryshe bllokimet. Psotimet publike mundet të jenë ende të dukshme për përdorues pa bërë hyrje në llogari.",
"block_modal.show_less": "اعرض أقلّ",
"block_modal.show_more": "أظهر المزيد",
"block_modal.they_cant_mention": "لن يستطيع ذِكرك أو متابعتك.",
"block_modal.they_cant_see_posts": "لن يستطيع رؤية منشوراتك ولن ترى منشوراته.",
"block_modal.they_will_know": "يمكنه أن يرى أنه قد تم حجبه.",
"block_modal.title": "أتريد حظر المستخدم؟",
"block_modal.you_wont_see_mentions": "لن تر المنشورات التي يُشار فيهم إليه.",
"boost_modal.combo": "يُمكنك الضّغط على {combo} لتخطي هذا في المرة المُقبلة",
"bundle_column_error.copy_stacktrace": "انسخ تقرير الخطأ",
"bundle_column_error.error.body": "لا يمكن تقديم الصفحة المطلوبة. قد يكون بسبب خطأ في التعليمات البرمجية، أو مشكلة توافق المتصفح.",
Expand Down Expand Up @@ -172,6 +177,7 @@
"confirmations.delete_list.message": "هل أنتَ مُتأكدٌ أنكَ تُريدُ حَذفَ هذِهِ القائمة بشكلٍ دائم؟",
"confirmations.discard_edit_media.confirm": "تجاهل",
"confirmations.discard_edit_media.message": "لديك تغييرات غير محفوظة لوصف الوسائط أو معاينتها، أتريد تجاهلها على أي حال؟",
"confirmations.domain_block.confirm": "حظر الخادم",
"confirmations.domain_block.message": "متأكد من أنك تود حظر اسم النطاق {domain} بالكامل ؟ في غالب الأحيان يُستَحسَن كتم أو حظر بعض الحسابات بدلا من حظر نطاق بالكامل.\nلن تتمكن مِن رؤية محتوى هذا النطاق لا على خيوطك العمومية و لا في إشعاراتك. سوف يتم كذلك إزالة كافة متابعيك المنتمين إلى هذا النطاق.",
"confirmations.edit.confirm": "تعديل",
"confirmations.edit.message": "التعديل في الحين سوف يُعيد كتابة الرسالة التي أنت بصدد تحريرها. متأكد من أنك تريد المواصلة؟",
Expand Down Expand Up @@ -203,6 +209,16 @@
"dismissable_banner.explore_statuses": "هذه هي المنشورات الرائجة على الشبكات الاجتماعيّة اليوم. تظهر المنشورات المعاد نشرها والحائزة على مفضّلات أكثر في مرتبة عليا.",
"dismissable_banner.explore_tags": "هذه هي الوسوم تكتسب جذب الاهتمام حاليًا على الويب الاجتماعي. الوسوم التي يستخدمها مختلف الناس تحتل مرتبة عليا.",
"dismissable_banner.public_timeline": "هذه هي أحدث المنشورات العامة من الناس على الشبكة الاجتماعية التي يتبعها الناس على {domain}.",
"domain_block_modal.block": "حظر الخادم",
"domain_block_modal.block_account_instead": "أحجب @{name} بدلاً من ذلك",
"domain_block_modal.they_can_interact_with_old_posts": "يمكن للأشخاص من هذا الخادم التفاعل مع منشوراتك القديمة.",
"domain_block_modal.they_cant_follow": "لا أحد من هذا الخادم يمكنه متابعتك.",
"domain_block_modal.they_wont_know": "لن يَعرف أنه قد تم حظره.",
"domain_block_modal.title": "أتريد حظر النطاق؟",
"domain_block_modal.you_will_lose_followers": "سيتم إزالة جميع متابعيك من هذا الخادم.",
"domain_block_modal.you_wont_see_posts": "لن ترى منشورات أو إشعارات من المستخدمين على هذا الخادم.",
"domain_pill.activitypub_lets_connect": "يتيح لك التواصل والتفاعل مع الناس ليس فقط على ماستدون، ولكن عبر تطبيقات اجتماعية مختلفة أيضا.",
"domain_pill.activitypub_like_language": "إنّ ActivityPub مثل لغة ماستدون التي يتحدث بها مع شبكات اجتماعية أخرى.",
"domain_pill.server": "الخادِم",
"domain_pill.their_handle": "مُعرِّفُه:",
"domain_pill.their_server": "بيتهم الرقمي، حيث تُستضاف كافة منشوراتهم.",
Expand Down Expand Up @@ -276,6 +292,7 @@
"filter_modal.select_filter.subtitle": "استخدم فئة موجودة أو قم بإنشاء فئة جديدة",
"filter_modal.select_filter.title": "تصفية هذا المنشور",
"filter_modal.title.status": "تصفية منشور",
"filtered_notifications_banner.title": "الإشعارات المصفاة",
"firehose.all": "الكل",
"firehose.local": "هذا الخادم",
"firehose.remote": "خوادم أخرى",
Expand Down Expand Up @@ -666,6 +683,7 @@
"status.direct": "إشارة خاصة لـ @{name}",
"status.direct_indicator": "إشارة خاصة",
"status.edit": "تعديل",
"status.edited": "آخر تعديل يوم {date}",
"status.edited_x_times": "عُدّل {count, plural, zero {} one {مرةً واحدة} two {مرّتان} few {{count} مرات} many {{count} مرة} other {{count} مرة}}",
"status.embed": "إدماج",
"status.favourite": "فضّل",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"filter_modal.select_filter.title": "Филтриране на публ.",
"filter_modal.title.status": "Филтриране на публ.",
"filtered_notifications_banner.pending_requests": "Известията от {count, plural, =0 {никого, когото може да познавате} one {едно лице, което може да познавате} other {# души, които може да познавате}}",
"filtered_notifications_banner.private_mentions": "{count, plural, one {частно споменаване} other {частни споменавания}}",
"filtered_notifications_banner.title": "Филтрирани известия",
"firehose.all": "Всичко",
"firehose.local": "Този сървър",
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"alert.rate_limited.message": "Bitte versuche es nach {retry_time, time, medium} erneut.",
"alert.rate_limited.title": "Anfragelimit überschritten",
"alert.unexpected.message": "Ein unerwarteter Fehler ist aufgetreten.",
"alert.unexpected.title": "Ups!",
"alert.unexpected.title": "Oha!",
"announcement.announcement": "Ankündigung",
"attachments_list.unprocessed": "(ausstehend)",
"audio.hide": "Audio ausblenden",
Expand Down
12 changes: 10 additions & 2 deletions app/javascript/mastodon/locales/gd.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"about.powered_by": "Lìonra sòisealta sgaoilte le cumhachd {mastodon}",
"about.rules": "Riaghailtean an fhrithealaiche",
"account.account_note_header": "Nòta",
"account.add_or_remove_from_list": "Cuir ris no thoir air falbh o na liostaichean",
"account.add_or_remove_from_list": "Cuir ris no thoir air falbh o liostaichean",
"account.badges.bot": "Fèin-obrachail",
"account.badges.group": "Buidheann",
"account.block": "Bac @{name}",
Expand Down Expand Up @@ -298,6 +298,7 @@
"filter_modal.select_filter.title": "Criathraich am post seo",
"filter_modal.title.status": "Criathraich post",
"filtered_notifications_banner.pending_requests": "{count, plural, =0 {Chan eil brath ann o dhaoine} one {Tha brathan ann o # neach} two {Tha brathan ann o # neach} few {Tha brathan ann o # daoine} other {Tha brathan ann o # duine}} air a bheil thu eòlach ’s dòcha",
"filtered_notifications_banner.private_mentions": "{count, plural, one {iomradh prìobhaideach} two {iomradh prìobhaideach} few {iomraidhean prìobhaideach} other {iomradh prìobhaideach}}",
"filtered_notifications_banner.title": "Brathan criathraichte",
"firehose.all": "Na h-uile",
"firehose.local": "Am frithealaiche seo",
Expand Down Expand Up @@ -471,6 +472,11 @@
"notification.own_poll": "Thàinig an cunntas-bheachd agad gu crìoch",
"notification.poll": "Thàinig cunntas-bheachd sa bhòt thu gu crìoch",
"notification.reblog": "Bhrosnaich {name} am post agad",
"notification.relationships_severance_event": "Chaill thu dàimhean le {name}",
"notification.relationships_severance_event.account_suspension": "Chuir rianaire aig {from} {target} à rèim agus is ciall dha sin nach fhaigh thu naidheachdan uapa ’s nach urrainn dhut conaltradh leotha.",
"notification.relationships_severance_event.domain_block": "Bhac rianaire aig {from} {target}, a’ gabhail a-staigh {followersCount} dhen luchd-leantainn agad agus {followingCount, plural, one {# chunntas} two {# chunntas} few {# cunntasan} other {# cunntas}} a tha thu fhèin a’ leantainn.",
"notification.relationships_severance_event.learn_more": "Barrachd fiosrachaidh",
"notification.relationships_severance_event.user_domain_block": "Bhac thu {target} agus thug sin air falbh {followersCount} dhen luchd-leantainn agad agus {followingCount, plural, one {# chunntas} two {# chunntas} few {# cunntasan} other {# cunntas}} a tha thu fhèin a’ leantainn.",
"notification.status": "Phostaich {name} rud",
"notification.update": "Dheasaich {name} post",
"notification_requests.accept": "Gabh ris",
Expand All @@ -483,6 +489,8 @@
"notifications.column_settings.admin.sign_up": "Clàraidhean ùra:",
"notifications.column_settings.alert": "Brathan deasga",
"notifications.column_settings.favourite": "Annsachdan:",
"notifications.column_settings.filter_bar.advanced": "Seall a h-uile roinn-seòrsa",
"notifications.column_settings.filter_bar.category": "Bàr-criathraidh luath",
"notifications.column_settings.follow": "Luchd-leantainn ùr:",
"notifications.column_settings.follow_request": "Iarrtasan leantainn ùra:",
"notifications.column_settings.mention": "Iomraidhean:",
Expand All @@ -508,7 +516,7 @@
"notifications.permission_denied": "Chan eil brathan deasga ri fhaighinn on a chaidh iarrtas ceadan a’ bhrabhsair a dhiùltadh cheana",
"notifications.permission_denied_alert": "Cha ghabh brathan deasga a chur an comas on a chaidh iarrtas ceadan a’ bhrabhsair a dhiùltadh cheana",
"notifications.permission_required": "Chan eil brathan deasga ri fhaighinn on nach deach an cead riatanach a thoirt seachad.",
"notifications.policy.filter_new_accounts.hint": "Chaidh a chruthachadh o chionn {days, plural, one {# latha} two {# latha} few {# làithean} other {# latha}}",
"notifications.policy.filter_new_accounts.hint": "A chaidh a chruthachadh o chionn {days, plural, one {# latha} two {# latha} few {# làithean} other {# latha}}",
"notifications.policy.filter_new_accounts_title": "Cunntasan ùra",
"notifications.policy.filter_not_followers_hint": "A’ gabhail a-staigh an fheadhainn a lean ort nas lugha na {days, plural, one {# latha} two {# latha} few {# làithean} other {# latha}} seo chaidh",
"notifications.policy.filter_not_followers_title": "Daoine nach eil gad leantainn",
Expand Down
5 changes: 5 additions & 0 deletions app/javascript/mastodon/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@
"notification.own_poll": "アンケートが終了しました",
"notification.poll": "アンケートが終了しました",
"notification.reblog": "{name}さんがあなたの投稿をブーストしました",
"notification.relationships_severance_event": "{name} との関係が失われました",
"notification.relationships_severance_event.account_suspension": "{from} の管理者が {target} さんを停止したため、今後このユーザーとの交流や新しい投稿の受け取りができなくなりました。",
"notification.relationships_severance_event.domain_block": "{from} の管理者が {target} をブロックしました。これにより{followersCount}フォロワーと{followingCount, plural, other {#フォロー}}が失われました。",
"notification.relationships_severance_event.learn_more": "詳細を確認",
"notification.relationships_severance_event.user_domain_block": "{target} のブロックにより{followersCount}フォロワーと{followingCount, plural, other {#フォロー}}が解除されました。",
"notification.status": "{name}さんが投稿しました",
"notification.status_reference": "{name}さんがあなたの投稿を引用しました",
"notification.update": "{name}さんが投稿を編集しました",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/lt.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"filter_modal.select_filter.subtitle": "Naudok esamą kategoriją arba sukurk naują.",
"filter_modal.select_filter.title": "Filtruoti šį įrašą",
"filter_modal.title.status": "Filtruoti įrašą",
"filtered_notifications_banner.private_mentions": "{count, plural, one {privatus paminėjimas} few {privatūs paminėjimai} many {privataus paminėjimo} other {privačių paminėjimų}}",
"firehose.all": "Visi",
"firehose.local": "Šis serveris",
"firehose.remote": "Kiti serveriai",
Expand Down
2 changes: 1 addition & 1 deletion app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FeedManager
# @yield [Account]
# @return [void]
def with_active_accounts(&block)
Account.joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).find_each(&block)
Account.joins(:user).merge(User.signed_in_recently).find_each(&block)
end

# Redis key of a feed
Expand Down
2 changes: 1 addition & 1 deletion app/lib/vacuum/feeds_vacuum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def vacuum_inactive_antenna_feeds!
end

def inactive_users
User.confirmed.inactive
User.confirmed.not_signed_in_recently
end

def inactive_users_lists
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/account/interactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ def status_matches_filters(status)
def followers_for_local_distribution
followers.local
.joins(:user)
.where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago)
.merge(User.signed_in_recently)
end

def lists_for_local_distribution
scope = lists.joins(account: :user)
scope.where.not(list_accounts: { follow_id: nil }).or(scope.where(account_id: id))
.where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago)
.merge(User.signed_in_recently)
end

def remote_followers_hash(url)
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/cacheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def with_includes
includes(@cache_associated)
end

def preload_cacheable_associations(records)
ActiveRecord::Associations::Preloader.new(records: records, associations: @cache_associated).call
end

def cache_ids
select(:id, :updated_at)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def from_redis(limit, max_id, since_id, min_id)
unhydrated = redis.zrangebyscore(key, "(#{min_id}", "(#{max_id}", limit: [0, limit], with_scores: true).map { |id| id.first.to_i }
end

Status.where(id: unhydrated).cache_ids
Status.where(id: unhydrated)
end

def key
Expand Down
2 changes: 1 addition & 1 deletion app/models/public_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get(limit, max_id = nil, since_id = nil, min_id = nil)
# scope.merge!(anonymous_scope) unless account?
scope = to_anonymous_scope(scope) unless account?

scope.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
scope.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
end

private
Expand Down
32 changes: 0 additions & 32 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,38 +559,6 @@ def emoji_reaction_availables_map(domains)
domains.index_with { |d| InstanceInfo.emoji_reaction_available?(d) }
end

def reload_stale_associations!(cached_items)
account_ids = []

cached_items.each do |item|
account_ids << item.account_id
account_ids << item.reblog.account_id if item.reblog?
end

account_ids.uniq!

status_ids = cached_items.map { |item| item.reblog? ? item.reblog_of_id : item.id }.uniq

return if account_ids.empty?

accounts = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)

status_stats = StatusStat.where(status_id: status_ids).index_by(&:status_id)

cached_items.each do |item|
item.account = accounts[item.account_id]
item.reblog.account = accounts[item.reblog.account_id] if item.reblog?

if item.reblog?
status_stat = status_stats[item.reblog.id]
item.reblog.status_stat = status_stat if status_stat.present?
else
status_stat = status_stats[item.id]
item.status_stat = status_stat if status_stat.present?
end
end
end

def from_text(text)
return [] if text.blank?

Expand Down
2 changes: 1 addition & 1 deletion app/models/tag_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get(limit, max_id = nil, since_id = nil, min_id = nil)
# scope.merge!(anonymous_scope) unless account?
scope = to_anonymous_scope(scope) unless account?

scope.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
scope.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
end

private
Expand Down
6 changes: 4 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ class User < ApplicationRecord
validates :confirm_password, absence: true, on: :create
validate :validate_role_elevation

scope :account_not_suspended, -> { joins(:account).merge(Account.without_suspended) }
scope :recent, -> { order(id: :desc) }
scope :pending, -> { where(approved: false) }
scope :approved, -> { where(approved: true) }
scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :enabled, -> { where(disabled: false) }
scope :disabled, -> { where(disabled: true) }
scope :inactive, -> { where(arel_table[:current_sign_in_at].lt(ACTIVE_DURATION.ago)) }
scope :active, -> { confirmed.where(arel_table[:current_sign_in_at].gteq(ACTIVE_DURATION.ago)).joins(:account).where(accounts: { suspended_at: nil }) }
scope :active, -> { confirmed.signed_in_recently.account_not_suspended }
scope :signed_in_recently, -> { where(current_sign_in_at: ACTIVE_DURATION.ago..) }
scope :not_signed_in_recently, -> { where(current_sign_in_at: ...ACTIVE_DURATION.ago) }
scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) }
scope :matches_ip, ->(value) { left_joins(:ips).where('user_ips.ip <<= ?', value).group('users.id') }

Expand Down
3 changes: 2 additions & 1 deletion app/views/application/mailer/_hashtag.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
%span.email-mini-hashtag-img-span
= image_tag full_asset_url(account.avatar.url), alt: '', width: 16, height: 16
%td
%p= t('user_mailer.welcome.hashtags_recent_count', people: number_with_delimiter(hashtag.history.aggregate(2.days.ago.to_date..Time.zone.today).accounts))
- people = hashtag.history.aggregate(2.days.ago.to_date..Time.zone.today).accounts
%p= t('user_mailer.welcome.hashtags_recent_count', people: number_with_delimiter(people), count: people)
Loading

0 comments on commit 6cf0f5b

Please sign in to comment.