From d0b14eaee2e6220f148bcc6e9fbdcce7e7ba4086 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 01:11:53 +0200 Subject: [PATCH 01/13] Add admin dashboard (#8029) --- app/controllers/admin/dashboard_controller.rb | 42 ++++++ app/javascript/styles/application.scss | 1 + app/javascript/styles/mastodon/dashboard.scss | 69 +++++++++ app/lib/potential_friendship_tracker.rb | 2 + app/views/admin/dashboard/index.html.haml | 140 ++++++++++++++++++ config/locales/en.yml | 20 +++ config/navigation.rb | 3 +- config/routes.rb | 10 +- 8 files changed, 279 insertions(+), 8 deletions(-) create mode 100644 app/controllers/admin/dashboard_controller.rb create mode 100644 app/javascript/styles/mastodon/dashboard.scss create mode 100644 app/views/admin/dashboard/index.html.haml diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 0000000000..01d4a98475 --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +require 'sidekiq/api' + +module Admin + class DashboardController < BaseController + def index + @users_count = User.count + @registrations_week = Redis.current.get("activity:accounts:local:#{current_week}") || 0 + @logins_week = Redis.current.pfcount("activity:logins:#{current_week}") + @interactions_week = Redis.current.get("activity:interactions:#{current_week}") || 0 + @relay_enabled = Relay.enabled.exists? + @single_user_mode = Rails.configuration.x.single_user_mode + @registrations_enabled = Setting.open_registrations + @deletions_enabled = Setting.open_deletions + @invites_enabled = Setting.min_invite_role == 'user' + @search_enabled = Chewy.enabled? + @version = Mastodon::Version.to_s + @database_version = ActiveRecord::Base.connection.execute('SELECT VERSION()').first['version'].match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1] + @redis_version = redis_info['redis_version'] + @reports_count = Report.unresolved.count + @queue_backlog = Sidekiq::Stats.new.enqueued + @recent_users = User.confirmed.recent.includes(:account).limit(4) + @database_size = ActiveRecord::Base.connection.execute('SELECT pg_database_size(current_database())').first['pg_database_size'] + @redis_size = redis_info['used_memory'] + @ldap_enabled = ENV['LDAP_ENABLED'] == 'true' + @cas_enabled = ENV['CAS_ENABLED'] == 'true' + @saml_enabled = ENV['SAML_ENABLED'] == 'true' + @pam_enabled = ENV['PAM_ENABLED'] == 'true' + @hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true' + end + + private + + def current_week + @current_week ||= Time.now.utc.to_date.cweek + end + + def redis_info + @redis_info ||= Redis.current.info + end + end +end diff --git a/app/javascript/styles/application.scss b/app/javascript/styles/application.scss index f207c02a6d..7b3b10dfe2 100644 --- a/app/javascript/styles/application.scss +++ b/app/javascript/styles/application.scss @@ -21,5 +21,6 @@ @import 'mastodon/about'; @import 'mastodon/tables'; @import 'mastodon/admin'; +@import 'mastodon/dashboard'; @import 'mastodon/rtl'; @import 'mastodon/accessibility'; diff --git a/app/javascript/styles/mastodon/dashboard.scss b/app/javascript/styles/mastodon/dashboard.scss new file mode 100644 index 0000000000..949ca733f4 --- /dev/null +++ b/app/javascript/styles/mastodon/dashboard.scss @@ -0,0 +1,69 @@ +.dashboard__counters { + display: flex; + flex-wrap: wrap; + margin: 0 -5px; + margin-bottom: 20px; + + & > div { + box-sizing: border-box; + flex: 0 0 33.333%; + padding: 0 5px; + margin-bottom: 10px; + + & > div, + & > a { + padding: 20px; + background: lighten($ui-base-color, 4%); + border-radius: 4px; + } + + & > a { + text-decoration: none; + color: inherit; + display: block; + + &:hover, + &:focus, + &:active { + background: lighten($ui-base-color, 8%); + } + } + } + + &__num { + text-align: center; + font-weight: 500; + font-size: 24px; + color: $primary-text-color; + font-family: 'mastodon-font-display', sans-serif; + margin-bottom: 20px; + } + + &__label { + font-size: 14px; + color: $darker-text-color; + text-align: center; + font-weight: 500; + } +} + +.dashboard__widgets { + display: flex; + flex-wrap: wrap; + margin: 0 -5px; + + & > div { + flex: 0 0 33.333%; + margin-bottom: 20px; + + & > div { + padding: 0 5px; + } + } + + a:not(.name-tag) { + color: $ui-secondary-color; + font-weight: 500; + text-decoration: none; + } +} diff --git a/app/lib/potential_friendship_tracker.rb b/app/lib/potential_friendship_tracker.rb index 017a9748d5..dfca54f7bc 100644 --- a/app/lib/potential_friendship_tracker.rb +++ b/app/lib/potential_friendship_tracker.rb @@ -20,6 +20,8 @@ class PotentialFriendshipTracker redis.zincrby(key, weight, target_account_id) redis.zremrangebyrank(key, 0, -MAX_ITEMS) redis.expire(key, EXPIRE_AFTER) + + ActivityTracker.increment('activity:interactions') end def remove(account_id, target_account_id) diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml new file mode 100644 index 0000000000..50004de33a --- /dev/null +++ b/app/views/admin/dashboard/index.html.haml @@ -0,0 +1,140 @@ +- content_for :page_title do + = t('admin.dashboard.title') + +.dashboard__counters + %div + = link_to admin_accounts_url(local: 1, recent: 1) do + .dashboard__counters__num= number_with_delimiter @users_count + .dashboard__counters__label= t 'admin.dashboard.total_users' + %div + %div + .dashboard__counters__num= number_with_delimiter @registrations_week + .dashboard__counters__label= t 'admin.dashboard.week_users_new' + %div + %div + .dashboard__counters__num= number_with_delimiter @logins_week + .dashboard__counters__label= t 'admin.dashboard.week_users_active' + %div + %div + .dashboard__counters__num= number_with_delimiter @interactions_week + .dashboard__counters__label= t 'admin.dashboard.week_interactions' + %div + = link_to admin_reports_url do + .dashboard__counters__num= number_with_delimiter @reports_count + .dashboard__counters__label= t 'admin.dashboard.open_reports' + %div + = link_to sidekiq_url do + .dashboard__counters__num= number_with_delimiter @queue_backlog + .dashboard__counters__label= t 'admin.dashboard.backlog' + +.dashboard__widgets + .dashboard__widgets__users + %div + %h4= t 'admin.dashboard.recent_users' + %ul + - @recent_users.each do |user| + %li= admin_account_link_to(user.account) + + .dashboard__widgets__features + %div + %h4= t 'admin.dashboard.features' + %ul + %li + = link_to t('admin.dashboard.feature_registrations'), edit_admin_settings_path + - if @registrations_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_invites'), edit_admin_settings_path + - if @invites_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_deletions'), edit_admin_settings_path + - if @deletions_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = link_to t('admin.dashboard.feature_relay'), admin_relays_path + - if @relay_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + + .dashboard__widgets__versions + %div + %h4= t 'admin.dashboard.software' + %ul + %li + Mastodon + %span.pull-right= @version + %li + Ruby + %span.pull-right= "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}" + %li + PostgreSQL + %span.pull-right= @database_version + %li + Redis + %span.pull-right= @redis_version + + .dashboard__widgets__space + %div + %h4= t 'admin.dashboard.space' + %ul + %li + PostgreSQL + %span.pull-right= number_to_human_size @database_size + %li + Redis + %span.pull-right= number_to_human_size @redis_size + + .dashboard__widgets__config + %div + %h4= t 'admin.dashboard.config' + %ul + %li + = t('admin.dashboard.search') + - if @search_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = t('admin.dashboard.single_user_mode') + - if @single_user_mode + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + LDAP + - if @ldap_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + CAS + - if @cas_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + SAML + - if @saml_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + PAM + - if @pam_enabled + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' + %li + = t 'admin.dashboard.hidden_service' + - if @hidden_service + %span.pull-right.positive-hint= fa_icon 'check fw' + - else + %span.pull-right.negative-hint= fa_icon 'times fw' diff --git a/config/locales/en.yml b/config/locales/en.yml index ec08f0d78a..e0a2c9f82f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -206,6 +206,26 @@ en: update_failed_msg: Could not update that emoji updated_msg: Emoji successfully updated! upload: Upload + dashboard: + backlog: backlogged jobs + config: Configuration + feature_deletions: Account deletions + feature_invites: Invite links + feature_registrations: Registrations + feature_relay: Federation relay + features: Features + hidden_service: Federation with hidden services + open_reports: open reports + recent_users: Recent users + search: Full-text search + single_user_mode: Single user mode + software: Software + space: Space usage + title: Dashboard + total_users: users in total + week_interactions: interactions this week + week_users_active: active this week + week_users_new: users this week domain_blocks: add_new: Add new created_msg: Domain block is now being processed diff --git a/config/navigation.rb b/config/navigation.rb index a13ad6f437..99d227f111 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -33,7 +33,8 @@ SimpleNavigation::Configuration.run do |navigation| admin.item :email_domain_blocks, safe_join([fa_icon('envelope fw'), t('admin.email_domain_blocks.title')]), admin_email_domain_blocks_url, highlights_on: %r{/admin/email_domain_blocks}, if: -> { current_user.admin? } end - primary.item :admin, safe_join([fa_icon('cogs fw'), t('admin.title')]), proc { current_user.admin? ? edit_admin_settings_url : admin_custom_emojis_url }, if: proc { current_user.staff? } do |admin| + primary.item :admin, safe_join([fa_icon('cogs fw'), t('admin.title')]), admin_dashboard_url, if: proc { current_user.staff? } do |admin| + admin.item :dashboard, safe_join([fa_icon('tachometer fw'), t('admin.dashboard.title')]), admin_dashboard_url admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url, if: -> { current_user.admin? } admin.item :custom_emojis, safe_join([fa_icon('smile-o fw'), t('admin.custom_emojis.title')]), admin_custom_emojis_url, highlights_on: %r{/admin/custom_emojis} admin.item :relays, safe_join([fa_icon('exchange fw'), t('admin.relays.title')]), admin_relays_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/relays} diff --git a/config/routes.rb b/config/routes.rb index 3d0da1a857..1c97f5a82c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,6 +124,8 @@ Rails.application.routes.draw do resource :share, only: [:show, :create] namespace :admin do + get '/dashboard', to: 'dashboard#index' + resources :subscriptions, only: [:index] resources :domain_blocks, only: [:index, :new, :create, :show, :destroy] resources :email_domain_blocks, only: [:index, :new, :create, :destroy] @@ -196,13 +198,7 @@ Rails.application.routes.draw do resources :account_moderation_notes, only: [:create, :destroy] end - authenticate :user, lambda { |u| u.admin? } do - get '/admin', to: redirect('/admin/settings/edit', status: 302) - end - - authenticate :user, lambda { |u| u.moderator? } do - get '/admin', to: redirect('/admin/reports', status: 302) - end + get '/admin', to: redirect('/admin/dashboard', status: 302) namespace :api do # PubSubHubbub outgoing subscriptions From 26bd3742e9fadbf6b9de2e348d4a9d808220af39 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 01:58:10 +0200 Subject: [PATCH 02/13] Fix typo in Admin::DashboardController#index --- app/controllers/admin/dashboard_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 01d4a98475..af1ac7b5e9 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -11,7 +11,7 @@ module Admin @relay_enabled = Relay.enabled.exists? @single_user_mode = Rails.configuration.x.single_user_mode @registrations_enabled = Setting.open_registrations - @deletions_enabled = Setting.open_deletions + @deletions_enabled = Setting.open_deletion @invites_enabled = Setting.min_invite_role == 'user' @search_enabled = Chewy.enabled? @version = Mastodon::Version.to_s From d1d46f914be69cf53f3b759e18e6c28a26d137a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Miko=C5=82ajczak?= Date: Mon, 16 Jul 2018 12:23:27 +0200 Subject: [PATCH 03/13] i18n: Update Polish translation (#8032) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Mikołajczak --- app/javascript/mastodon/locales/pl.json | 2 +- config/locales/pl.yml | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/locales/pl.json b/app/javascript/mastodon/locales/pl.json index 4f1290121b..bcb015968e 100644 --- a/app/javascript/mastodon/locales/pl.json +++ b/app/javascript/mastodon/locales/pl.json @@ -166,7 +166,7 @@ "navigation_bar.domain_blocks": "Ukryte domeny", "navigation_bar.edit_profile": "Edytuj profil", "navigation_bar.favourites": "Ulubione", - "navigation_bar.filters": "Muted words", + "navigation_bar.filters": "Wyciszone słowa", "navigation_bar.follow_requests": "Prośby o śledzenie", "navigation_bar.info": "Szczegółowe informacje", "navigation_bar.keyboard_shortcuts": "Skróty klawiszowe", diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 061c07b640..62e2b59ae4 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -206,6 +206,26 @@ pl: update_failed_msg: Nie udało się zaktualizować emoji updated_msg: Pomyślnie zaktualizowano emoji! upload: Dodaj + dashboard: + backlog: zaległe zadania + config: Konfiguracja + feature_deletions: Usuwanie kont + feature_invites: Zaproszenia + feature_registrations: Rejestracja + feature_relay: Przekazywanie federacji + features: Możliwości + hidden_service: Federowanie z ukrytymi usługami + open_reports: otwarte zgłoszenia + recent_users: Ostatni użytkownicy + search: Wyszukiwanie pełnego tekstu + single_user_mode: Tryb jednego użytkownika + software: Oprogramowanie + space: Używana powierzchnia + title: Panel administracyjny + total_users: łącznie użytkowników + week_interactions: interakcje w tym tygodniu + week_users_active: aktywni w tym tygodniu + week_users_new: rejestracje w tym tygodniu domain_blocks: add_new: Dodaj nową created_msg: Blokada domen jest przetwarzana @@ -262,6 +282,14 @@ pl: expired: Wygasłe title: Filtruj title: Zaproszenia + relays: + add_new: Dodaj nowy + description_html: "Przekaźnik federacji jest pośredniczącym serwerem wymieniającym duże ilości publicznych wpisów pomiędzy serwerami które subskrybują je i publikują na nich. Pomaga to małym i średnim instancją poznawać nową zawartość z Fediwersum, co w innym przypadku wymagałoby od użytkowników ręcznego śledzenia osób z innych serwerów." + enable_hint: Jeżeli włączone, Twój serwer zasubskrybuje wszystkie publiczne wpisy z tego przekaźnika i zacznie wysyłać tam publiczne wpisy z tego serwera. + inbox_url: Adres przekaźnika + setup: Skonfiguruj połączenie z przekaźnikiem + status: Stan + title: Przekaźniki report_notes: created_msg: Pomyslnie utworzono notatkę moderacyjną. destroyed_msg: Pomyślnie usunięto notatkę moderacyjną. From b751ec1c2e1c509aa704c0d6c9210724b0e5984e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 15:17:43 +0200 Subject: [PATCH 04/13] Whitelist dat/ipfs/gopher links in sanitizer (#8034) Fix #7994 --- app/lib/sanitize_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index c2b4669245..1bba4a5a6e 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -2,7 +2,7 @@ class Sanitize module Config - HTTP_PROTOCOLS ||= ['http', 'https', :relative].freeze + HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', :relative].freeze CLASS_WHITELIST_TRANSFORMER = lambda do |env| node = env[:node] From 38f413e5835d72b9b586464065937747fabc7c89 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 18:35:43 +0200 Subject: [PATCH 05/13] Fix activity:interactions counter to count all interactions (#8037) --- app/lib/potential_friendship_tracker.rb | 2 -- app/services/favourite_service.rb | 1 + app/services/post_status_service.rb | 4 +++- app/services/reblog_service.rb | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/lib/potential_friendship_tracker.rb b/app/lib/potential_friendship_tracker.rb index dfca54f7bc..017a9748d5 100644 --- a/app/lib/potential_friendship_tracker.rb +++ b/app/lib/potential_friendship_tracker.rb @@ -20,8 +20,6 @@ class PotentialFriendshipTracker redis.zincrby(key, weight, target_account_id) redis.zremrangebyrank(key, 0, -MAX_ITEMS) redis.expire(key, EXPIRE_AFTER) - - ActivityTracker.increment('activity:interactions') end def remove(account_id, target_account_id) diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index 6e1ac3ba99..b565bcc320 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -37,6 +37,7 @@ class FavouriteService < BaseService end def bump_potential_friendship(account, status) + ActivityTracker.increment('activity:interactions') return if account.following?(status.account_id) PotentialFriendshipTracker.record(account.id, status.account_id, :favourite) end diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 4c3485853d..300eae547a 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -83,7 +83,9 @@ class PostStatusService < BaseService end def bump_potential_friendship(account, status) - return if !status.reply? || account.following?(status.in_reply_to_account_id) + return if !status.reply? || account.id == status.in_reply_to_account_id + ActivityTracker.increment('activity:interactions') + return if account.following?(status.in_reply_to_account_id) PotentialFriendshipTracker.record(account.id, status.in_reply_to_account_id, :reply) end end diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 0ee8bac2f2..33ddef8b88 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -44,6 +44,7 @@ class ReblogService < BaseService end def bump_potential_friendship(account, reblog) + ActivityTracker.increment('activity:interactions') return if account.following?(reblog.reblog.account_id) PotentialFriendshipTracker.record(account.id, reblog.reblog.account_id, :reblog) end From 77d8396217b51e74d59d493b721b74f2fee3c32a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 18:43:22 +0200 Subject: [PATCH 06/13] Fix ActivityPub::UpdateDistributionWorker regression (#8039) Regression from #7998 let to profile updates not sending --- app/workers/activitypub/update_distribution_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/activitypub/update_distribution_worker.rb b/app/workers/activitypub/update_distribution_worker.rb index 87efafb3e8..bbda693059 100644 --- a/app/workers/activitypub/update_distribution_worker.rb +++ b/app/workers/activitypub/update_distribution_worker.rb @@ -34,6 +34,6 @@ class ActivityPub::UpdateDistributionWorker @account, serializer: ActivityPub::UpdateSerializer, adapter: ActivityPub::Adapter - ).to_json + ).as_json end end From 2f6967913aaec9556929ea6c2aaae54da3ca9707 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 19:21:27 +0200 Subject: [PATCH 07/13] Display trending hashtags on admin dashboard (#8038) --- app/controllers/admin/dashboard_controller.rb | 1 + app/models/trending_tags.rb | 27 +++++++++++++++++++ app/views/admin/dashboard/index.html.haml | 9 +++++++ 3 files changed, 37 insertions(+) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index af1ac7b5e9..7be753c9b3 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -27,6 +27,7 @@ module Admin @saml_enabled = ENV['SAML_ENABLED'] == 'true' @pam_enabled = ENV['PAM_ENABLED'] == 'true' @hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true' + @trending_hashtags = TrendingTags.get(7) end private diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index c3641d7fd9..b11f352929 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class TrendingTags + KEY = 'trending_tags' EXPIRE_HISTORY_AFTER = 7.days.seconds + EXPIRE_TRENDS_AFTER = 1.day.seconds + THRESHOLD = 5 class << self def record_use!(tag, account, at_time = Time.now.utc) @@ -9,6 +12,14 @@ class TrendingTags increment_historical_use!(tag.id, at_time) increment_unique_use!(tag.id, account.id, at_time) + increment_vote!(tag.id, at_time) + end + + def get(limit) + key = "#{KEY}:#{Time.now.utc.beginning_of_day.to_i}" + tag_ids = redis.zrevrange(key, 0, limit).map(&:to_i) + tags = Tag.where(id: tag_ids).to_a.map { |tag| [tag.id, tag] }.to_h + tag_ids.map { |tag_id| tags[tag_id] }.compact end private @@ -25,6 +36,22 @@ class TrendingTags redis.expire(key, EXPIRE_HISTORY_AFTER) end + def increment_vote!(tag_id, at_time) + key = "#{KEY}:#{at_time.beginning_of_day.to_i}" + expected = redis.pfcount("activity:tags:#{tag_id}:#{(at_time - 1.day).beginning_of_day.to_i}:accounts").to_f + expected = 1.0 if expected.zero? + observed = redis.pfcount("activity:tags:#{tag_id}:#{at_time.beginning_of_day.to_i}:accounts").to_f + + if expected > observed || observed < THRESHOLD + redis.zrem(key, tag_id.to_s) + else + score = ((observed - expected)**2) / expected + redis.zadd(key, score, tag_id.to_s) + end + + redis.expire(key, EXPIRE_TRENDS_AFTER) + end + def disallowed_hashtags return @disallowed_hashtags if defined?(@disallowed_hashtags) diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index 50004de33a..41a0ee5a1d 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -138,3 +138,12 @@ %span.pull-right.positive-hint= fa_icon 'check fw' - else %span.pull-right.negative-hint= fa_icon 'times fw' + + .dashboard__widgets__trends + %div + %h4= t 'admin.dashboard.trends' + %ul + - @trending_hashtags.each do |tag| + %li + = link_to "##{tag.name}", web_url("timelines/tag/#{tag.name}") + %span.pull-right= number_with_delimiter(tag.history[0]['accounts'].to_i) From d987567b398cbb6c74624ba6a1db7157aff169b3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 19:51:16 +0200 Subject: [PATCH 08/13] Fix tag usage display on admin dashboard --- app/views/admin/dashboard/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index 41a0ee5a1d..1996eef4d2 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -146,4 +146,4 @@ - @trending_hashtags.each do |tag| %li = link_to "##{tag.name}", web_url("timelines/tag/#{tag.name}") - %span.pull-right= number_with_delimiter(tag.history[0]['accounts'].to_i) + %span.pull-right= number_with_delimiter(tag.history[0][:accounts].to_i) From 56fdbc04b3b136cb6a4d7bd1718befa7655f038e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Jul 2018 19:54:14 +0200 Subject: [PATCH 09/13] Fix number of results returned from TrendingTags.get --- app/models/trending_tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index b11f352929..c559651c66 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -17,7 +17,7 @@ class TrendingTags def get(limit) key = "#{KEY}:#{Time.now.utc.beginning_of_day.to_i}" - tag_ids = redis.zrevrange(key, 0, limit).map(&:to_i) + tag_ids = redis.zrevrange(key, 0, limit - 1).map(&:to_i) tags = Tag.where(id: tag_ids).to_a.map { |tag| [tag.id, tag] }.to_h tag_ids.map { |tag_id| tags[tag_id] }.compact end From 8ccb57f8a60fbdea7c9f8c5acbfe3ef583afd516 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 17 Jul 2018 00:15:17 +0200 Subject: [PATCH 10/13] Add missing translation for admin dashboard trends section (#8040) --- config/locales/en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index e0a2c9f82f..f89f89959d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -223,6 +223,7 @@ en: space: Space usage title: Dashboard total_users: users in total + trends: Trends week_interactions: interactions this week week_users_active: active this week week_users_new: users this week From dd5b6bf3bbfb27461b1b19fb80b3c48ac0eb47c1 Mon Sep 17 00:00:00 2001 From: abcang Date: Tue, 17 Jul 2018 22:29:33 +0900 Subject: [PATCH 11/13] Update supported Node.js version (#8041) --- config/webpack/production.js | 2 +- package.json | 5 ++--- yarn.lock | 20 +------------------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/config/webpack/production.js b/config/webpack/production.js index 58c7fa69a2..4966807a15 100644 --- a/config/webpack/production.js +++ b/config/webpack/production.js @@ -8,7 +8,7 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl const OfflinePlugin = require('offline-plugin'); const { publicPath } = require('./configuration.js'); const path = require('path'); -const { URL } = require('whatwg-url'); +const { URL } = require('url'); let compressionAlgorithm; try { diff --git a/package.json b/package.json index fdd8c3642a..b0cdf562d2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "mastodon", "license": "AGPL-3.0-or-later", "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "postversion": "git push --tags", @@ -122,8 +122,7 @@ "webpack-cli": "^3.0.8", "webpack-manifest-plugin": "^2.0.3", "webpack-merge": "^4.1.3", - "websocket.js": "^0.1.12", - "whatwg-url": "^6.4.1" + "websocket.js": "^0.1.12" }, "devDependencies": { "babel-eslint": "^8.2.6", diff --git a/yarn.lock b/yarn.lock index 423623300f..2c257ff0ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4858,10 +4858,6 @@ lodash.mergewith@^4.6.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927" -lodash.sortby@^4.7.0: - version "4.7.0" - resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" - lodash.tail@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/lodash.tail/-/lodash.tail-4.1.1.tgz#d2333a36d9e7717c8ad2f7cacafec7c32b444664" @@ -8173,12 +8169,6 @@ tough-cookie@~2.3.0, tough-cookie@~2.3.3: dependencies: punycode "^1.4.1" -tr46@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09" - dependencies: - punycode "^2.1.0" - tr46@~0.0.3: version "0.0.3" resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" @@ -8469,7 +8459,7 @@ webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" -webidl-conversions@^4.0.0, webidl-conversions@^4.0.2: +webidl-conversions@^4.0.0: version "4.0.2" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" @@ -8645,14 +8635,6 @@ whatwg-url@^4.3.0: tr46 "~0.0.3" webidl-conversions "^3.0.0" -whatwg-url@^6.4.1: - version "6.5.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8" - dependencies: - lodash.sortby "^4.7.0" - tr46 "^1.0.1" - webidl-conversions "^4.0.2" - whet.extend@~0.9.9: version "0.9.9" resolved "https://registry.yarnpkg.com/whet.extend/-/whet.extend-0.9.9.tgz#f877d5bf648c97e5aa542fadc16d6a259b9c11a1" From 8058ec5a1320372ec63b8785067b33c30ea62a08 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 17 Jul 2018 18:54:07 +0200 Subject: [PATCH 12/13] Ensure container of React components has full width (#8043) Fix #8018 --- app/javascript/styles/mastodon/stream_entries.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/javascript/styles/mastodon/stream_entries.scss b/app/javascript/styles/mastodon/stream_entries.scss index 9188c22064..f4d6e237f6 100644 --- a/app/javascript/styles/mastodon/stream_entries.scss +++ b/app/javascript/styles/mastodon/stream_entries.scss @@ -2,6 +2,10 @@ clear: both; box-shadow: 0 0 15px rgba($base-shadow-color, 0.2); + div[data-component] { + width: 100%; + } + .entry { background: $simple-background-color; From cc3a3f579a393aec85933d41fcd61d7a7912b15a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 17 Jul 2018 21:44:11 +0200 Subject: [PATCH 13/13] Hide "A look inside" in mobile layout on frontpage (#8044) --- app/javascript/styles/mastodon/about.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/styles/mastodon/about.scss b/app/javascript/styles/mastodon/about.scss index 19e14fe952..fefb03407c 100644 --- a/app/javascript/styles/mastodon/about.scss +++ b/app/javascript/styles/mastodon/about.scss @@ -923,7 +923,7 @@ $small-breakpoint: 960px; } @media screen and (max-width: $column-breakpoint) { - height: 90vh; + display: none; } }