From 9d4f18b984d6699bdf96e5f5963edfe80063426c Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sat, 27 Jun 2020 14:22:30 -0500 Subject: Monsterfork v2 Kaiju Commit 2020.06.27.1 - 2020.09.05.5 --- lib/mastodon/snowflake.rb | 13 +------------ lib/mastodon/version.rb | 41 ++++++++++++++++++++++++++++++++++++++--- lib/tasks/monsterfork.rake | 22 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 lib/tasks/monsterfork.rake (limited to 'lib') diff --git a/lib/mastodon/snowflake.rb b/lib/mastodon/snowflake.rb index 9e5bc7383..10ed51f0c 100644 --- a/lib/mastodon/snowflake.rb +++ b/lib/mastodon/snowflake.rb @@ -120,21 +120,10 @@ module Mastodon::Snowflake seq_name = data[:seq_prefix] + '_id_seq' - # If we were on Postgres 9.5+, we could do CREATE SEQUENCE IF - # NOT EXISTS, but we can't depend on that. Instead, catch the - # possible exception and ignore it. # Note that seq_name isn't a column name, but it's a # relation, like a column, and follows the same quoting rules # in Postgres. - connection.execute(<<~SQL) - DO $$ - BEGIN - CREATE SEQUENCE #{connection.quote_column_name(seq_name)}; - EXCEPTION WHEN duplicate_table THEN - -- Do nothing, we have the sequence already. - END - $$ LANGUAGE plpgsql; - SQL + connection.execute("CREATE SEQUENCE IF NOT EXISTS #{connection.quote_column_name(seq_name)};") end end diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 429bcb8a5..448518884 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -21,7 +21,7 @@ module Mastodon end def suffix - '+glitch' + '+glitch+monsterpit' end def to_a @@ -33,11 +33,11 @@ module Mastodon end def repository - ENV.fetch('GITHUB_REPOSITORY', 'glitch-soc/mastodon') + ENV.fetch('GITHUB_REPOSITORY') { 'monsterpit/monsterpit-mastodon' } end def source_base_url - ENV.fetch('SOURCE_BASE_URL', "https://github.com/#{repository}") + ENV.fetch('SOURCE_BASE_URL') { "https://monsterware.dev/#{repository}" } end # specify git tag or commit hash here @@ -56,5 +56,40 @@ module Mastodon def user_agent @user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Version}; +http#{Rails.configuration.x.use_https ? 's' : ''}://#{Rails.configuration.x.web_domain}/)" end + + def server_metadata_json + @server_metadata_json ||= [ + { + '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' }, + type: 'PropertyValue', + name: 'version', + value: to_s, + }, + { + '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' }, + type: 'PropertyValue', + name: 'monsterpit:extensions', + value: '2020.09.05.1', + }, + { + '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' }, + type: 'PropertyValue', + name: 'comment:0', + value: "big tails can't fail", + }, + { + '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' }, + type: 'PropertyValue', + name: 'comment:1', + value: 'trans rights!', + }, + { + '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' }, + type: 'PropertyValue', + name: 'comment:2', + value: 'gently the kobolds', + }, + ] + end end end diff --git a/lib/tasks/monsterfork.rake b/lib/tasks/monsterfork.rake new file mode 100644 index 000000000..041bdac3c --- /dev/null +++ b/lib/tasks/monsterfork.rake @@ -0,0 +1,22 @@ +# frozen_string_literal: true +namespace :monsterfork do + desc 'Compute post nesting levels (this may take a very long time!)' + task compute_nesting_levels: :environment do + Rails.logger.info('Setting post nesting level for orphaned replies...') + Status.select(:id, :account_id).where(reply: true, in_reply_to_id: nil).reorder(nil).in_batches.update_all(nest_level: 1) + + count = 1.0 + total = Conversation.count + + Conversation.reorder('conversations.id DESC').find_each do |conversation| + Rails.logger.info("(#{(count / total * 100).to_i}%) Computing post nesting levels for all threads...") + + conversation.statuses.where(reply: true).reorder('statuses.id ASC').find_each do |status| + level = [status.thread&.account_id == status.account_id ? status.thread&.nest_level.to_i : status.thread&.nest_level.to_i + 1, 127].min + status.update(nest_level: level) if level != status.nest_level + end + + count += 1 + end + end +end -- cgit