DEV: update syntax tree to latest (#24623)

update format to latest syntax tree
This commit is contained in:
Sam 2023-11-29 16:38:07 +11:00 committed by GitHub
parent d40c0b698c
commit b09422428d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 123 additions and 124 deletions

View File

@ -484,7 +484,7 @@ GEM
sprockets (>= 3.0.0)
sshkey (3.0.0)
stackprof (0.2.25)
syntax_tree (6.1.1)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
syntax_tree-disable_ternary (1.0.0)
test-prof (1.3.0)

View File

@ -14,7 +14,6 @@ class Admin::ApiController < Admin::AdminController
ApiKey
.where(hidden: false)
.includes(:user, :api_key_scopes)
# Sort revoked keys by revoked_at and active keys by created_at
.order("revoked_at DESC NULLS FIRST, created_at DESC")
.offset(offset)
.limit(limit)

View File

@ -33,11 +33,11 @@ module Jobs
.where(
"uploads.retain_hours IS NULL OR uploads.created_at < current_timestamp - interval '1 hour' * uploads.retain_hours",
)
.where("uploads.created_at < ?", grace_period.hour.ago)
# Don't remove any secure uploads.
.where("uploads.created_at < ?", grace_period.hour.ago) # Don't remove any secure uploads.
.where("uploads.access_control_post_id IS NULL")
.joins("LEFT JOIN upload_references ON upload_references.upload_id = uploads.id")
# Don't remove any uploads linked to an UploadReference.
.joins(
"LEFT JOIN upload_references ON upload_references.upload_id = uploads.id",
) # Don't remove any uploads linked to an UploadReference.
.where("upload_references.upload_id IS NULL")
.with_no_non_post_relations

View File

@ -12,10 +12,10 @@ class ApiKey < ActiveRecord::Base
scope :revoked, -> { where("revoked_at IS NOT NULL") }
scope :with_key,
->(key) {
->(key) do
hashed = self.hash_key(key)
where(key_hash: hashed)
}
end
validates :description, length: { maximum: 255 }

View File

@ -130,14 +130,14 @@ class Bookmark < ActiveRecord::Base
scope :with_reminders, -> { where("reminder_at IS NOT NULL") }
scope :pending_reminders,
->(before_time = Time.now.utc) {
->(before_time = Time.now.utc) do
with_reminders.where("reminder_at <= ?", before_time).where(reminder_last_sent_at: nil)
}
end
scope :pending_reminders_for_user, ->(user) { pending_reminders.where(user: user) }
scope :for_user_in_topic,
->(user_id, topic_id) {
->(user_id, topic_id) do
joins(
"LEFT JOIN posts ON posts.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Post'",
).joins(
@ -149,7 +149,7 @@ class Bookmark < ActiveRecord::Base
user_id: user_id,
topic_id: topic_id,
)
}
end
def self.count_per_day(opts = nil)
opts ||= {}

View File

@ -170,7 +170,7 @@ class Category < ActiveRecord::Base
scope :latest, -> { order("topic_count DESC") }
scope :secured,
->(guardian = nil) {
->(guardian = nil) do
ids = guardian.secure_category_ids if guardian
if ids.present?
@ -181,13 +181,13 @@ class Category < ActiveRecord::Base
else
where("NOT categories.read_restricted").references(:categories)
end
}
end
TOPIC_CREATION_PERMISSIONS ||= [:full]
POST_CREATION_PERMISSIONS ||= %i[create_post full]
scope :topic_create_allowed,
->(guardian) {
->(guardian) do
scoped = scoped_to_permissions(guardian, TOPIC_CREATION_PERMISSIONS)
if !SiteSetting.allow_uncategorized_topics && !guardian.is_staff?
@ -195,7 +195,7 @@ class Category < ActiveRecord::Base
end
scoped
}
end
scope :post_create_allowed,
->(guardian) { scoped_to_permissions(guardian, POST_CREATION_PERMISSIONS) }

View File

@ -10,12 +10,12 @@ class EmailToken < ActiveRecord::Base
scope :unconfirmed, -> { where(confirmed: false) }
scope :active,
-> {
-> do
where(expired: false).where(
"created_at >= ?",
SiteSetting.email_token_valid_hours.hours.ago,
)
}
end
after_initialize do
if self.token_hash.blank?

View File

@ -17,22 +17,22 @@ class ExternalUploadStub < ActiveRecord::Base
}
scope :expired_created,
-> {
-> do
where(
"status = ? AND created_at <= ?",
ExternalUploadStub.statuses[:created],
CREATED_EXPIRY_HOURS.hours.ago,
)
}
end
scope :expired_uploaded,
-> {
-> do
where(
"status = ? AND created_at <= ?",
ExternalUploadStub.statuses[:uploaded],
UPLOADED_EXPIRY_HOURS.hours.ago,
)
}
end
before_create do
self.unique_identifier = SecureRandom.uuid

View File

@ -25,14 +25,14 @@ class Notification < ActiveRecord::Base
}
scope :unread_type, ->(user, type, limit = 30) { unread_types(user, [type], limit) }
scope :unread_types,
->(user, types, limit = 30) {
->(user, types, limit = 30) do
where(user_id: user.id, read: false, notification_type: types)
.visible
.includes(:topic)
.limit(limit)
}
end
scope :prioritized,
->(deprioritized_types = []) {
->(deprioritized_types = []) do
scope = order("notifications.high_priority AND NOT notifications.read DESC")
if deprioritized_types.present?
scope =
@ -46,11 +46,11 @@ class Notification < ActiveRecord::Base
scope = scope.order("NOT notifications.read DESC")
end
scope.order("notifications.created_at DESC")
}
end
scope :for_user_menu,
->(user_id, limit: 30) {
->(user_id, limit: 30) do
where(user_id: user_id).visible.prioritized.includes(:topic).limit(limit)
}
end
attr_accessor :skip_send_email

View File

@ -89,13 +89,13 @@ class Post < ActiveRecord::Base
register_custom_field_type(NOTICE, :json)
scope :private_posts_for_user,
->(user) {
->(user) do
where(
"topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_USER})
OR topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_GROUP})",
user_id: user.id,
)
}
end
scope :by_newest, -> { order("created_at DESC, id DESC") }
scope :by_post_number, -> { order("post_number ASC") }
@ -111,7 +111,7 @@ class Post < ActiveRecord::Base
->(guardian) { where("posts.post_type IN (?)", Topic.visible_post_types(guardian&.user)) }
scope :for_mailing_list,
->(user, since) {
->(user, since) do
q =
created_since(since).joins(
"INNER JOIN (#{Topic.for_digest(user, Time.at(0)).select(:id).to_sql}) AS digest_topics ON digest_topics.id = posts.topic_id",
@ -120,10 +120,10 @@ class Post < ActiveRecord::Base
q = q.where.not(post_type: Post.types[:whisper]) unless user.staff?
q
}
end
scope :raw_match,
->(pattern, type = "string") {
->(pattern, type = "string") do
type = type&.downcase
case type
@ -132,10 +132,10 @@ class Post < ActiveRecord::Base
when "regex"
where("raw ~* ?", "(?n)#{pattern}")
end
}
end
scope :have_uploads,
-> {
-> do
where(
"
(
@ -151,7 +151,7 @@ class Post < ActiveRecord::Base
)",
"%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%",
)
}
end
delegate :username, to: :user

View File

@ -34,11 +34,11 @@ class RemoteTheme < ActiveRecord::Base
has_one :theme, autosave: false
scope :joined_remotes,
-> {
-> do
joins("JOIN themes ON themes.remote_theme_id = remote_themes.id").where.not(
remote_url: "",
)
}
end
validates_format_of :minimum_discourse_version,
:maximum_discourse_version,

View File

@ -22,18 +22,18 @@ class Tag < ActiveRecord::Base
validates :description, length: { maximum: 1000 }
scope :where_name,
->(name) {
->(name) do
name = Array(name).map(&:downcase)
where("lower(tags.name) IN (?)", name)
}
end
# tags that have never been used and don't belong to a tag group
scope :unused,
-> {
-> do
where(staff_topic_count: 0, pm_topic_count: 0, target_tag_id: nil).joins(
"LEFT JOIN tag_group_memberships tgm ON tags.id = tgm.tag_id",
).where("tgm.tag_id IS NULL")
}
end
scope :used_tags_in_regular_topics,
->(guardian) { where("tags.#{Tag.topic_count_column(guardian)} > 0") }

View File

@ -5,7 +5,7 @@ class TagUser < ActiveRecord::Base
belongs_to :user
scope :notification_level_visible,
->(notification_levels = TagUser.notification_levels.values) {
->(notification_levels = TagUser.notification_levels.values) do
select("tag_users.*")
.distinct
.joins(
@ -24,7 +24,7 @@ class TagUser < ActiveRecord::Base
everyone_group_id: Group::AUTO_GROUPS[:everyone],
notification_levels: notification_levels,
)
}
end
def self.notification_levels
NotificationLevels.all

View File

@ -75,7 +75,7 @@ class Theme < ActiveRecord::Base
scope :user_selectable, -> { where("user_selectable OR id = ?", SiteSetting.default_theme_id) }
scope :include_relations,
-> {
-> do
includes(
:child_themes,
:parent_themes,
@ -88,7 +88,7 @@ class Theme < ActiveRecord::Base
:theme_translation_overrides,
theme_fields: :upload,
)
}
end
def notify_color_change(color, scheme: nil)
scheme ||= color.color_scheme

View File

@ -19,7 +19,7 @@ class ThemeField < ActiveRecord::Base
end
scope :find_by_theme_ids,
->(theme_ids) {
->(theme_ids) do
return none unless theme_ids.present?
where(theme_id: theme_ids).joins(
@ -27,10 +27,10 @@ class ThemeField < ActiveRecord::Base
SELECT #{theme_ids.map.with_index { |id, idx| "#{id.to_i} AS theme_id, #{idx} AS theme_sort_column" }.join(" UNION ALL SELECT ")}
) as X ON X.theme_id = theme_fields.theme_id",
).order("theme_sort_column")
}
end
scope :filter_locale_fields,
->(locale_codes) {
->(locale_codes) do
return none unless locale_codes.present?
where(target_id: Theme.targets[:translations], name: locale_codes).joins(
@ -41,20 +41,20 @@ class ThemeField < ActiveRecord::Base
*locale_codes.map.with_index { |code, index| [code, index] },
),
).order("Y.locale_sort_column")
}
end
scope :find_first_locale_fields,
->(theme_ids, locale_codes) {
->(theme_ids, locale_codes) do
find_by_theme_ids(theme_ids)
.filter_locale_fields(locale_codes)
.reorder("X.theme_sort_column", "Y.locale_sort_column")
.select("DISTINCT ON (X.theme_sort_column) *")
}
end
scope :svg_sprite_fields,
-> {
-> do
where(type_id: ThemeField.theme_var_type_ids, name: SvgSprite.theme_sprite_variable_name)
}
end
def self.types
@types ||=

View File

@ -317,13 +317,13 @@ class Topic < ActiveRecord::Base
SQL
scope :private_messages_for_user,
->(user) {
->(user) do
private_messages.where(
"topics.id IN (#{PRIVATE_MESSAGES_SQL_USER})
OR topics.id IN (#{PRIVATE_MESSAGES_SQL_GROUP})",
user_id: user.id,
)
}
end
scope :listable_topics, -> { where("topics.archetype <> ?", Archetype.private_message) }

View File

@ -23,9 +23,9 @@ class TopicTimer < ActiveRecord::Base
scope :scheduled_bump_topics,
-> { where(status_type: TopicTimer.types[:bump], deleted_at: nil).pluck(:topic_id) }
scope :pending_timers,
->(before_time = Time.now.utc) {
->(before_time = Time.now.utc) do
where("execute_at <= :before_time AND deleted_at IS NULL", before_time: before_time)
}
end
before_save do
self.created_at ||= Time.zone.now if execute_at

View File

@ -103,7 +103,7 @@ class User < ActiveRecord::Base
has_many :badges, through: :user_badges
has_many :default_featured_user_badges,
-> {
-> do
max_featured_rank =
(
if SiteSetting.max_favorite_badges > 0
@ -113,7 +113,7 @@ class User < ActiveRecord::Base
end
)
for_enabled_badges.grouped_with_count.where("featured_rank <= ?", max_featured_rank)
},
end,
class_name: "UserBadge"
has_many :topics_allowed, through: :topic_allowed_users, source: :topic
@ -249,18 +249,18 @@ class User < ActiveRecord::Base
->(email) { joins(:user_emails).where("lower(user_emails.email) IN (?)", email) }
scope :with_primary_email,
->(email) {
->(email) do
joins(:user_emails).where(
"lower(user_emails.email) IN (?) AND user_emails.primary",
email,
)
}
end
scope :human_users, -> { where("users.id > 0") }
# excluding fake users like the system user or anonymous users
scope :real,
-> {
-> do
human_users.where(
"NOT EXISTS(
SELECT 1
@ -268,7 +268,7 @@ class User < ActiveRecord::Base
WHERE a.user_id = users.id
)",
)
}
end
# TODO-PERF: There is no indexes on any of these
# and NotifyMailingListSubscribers does a select-all-and-loop
@ -281,16 +281,16 @@ class User < ActiveRecord::Base
scope :not_staged, -> { where(staged: false) }
scope :filter_by_username,
->(filter) {
->(filter) do
if filter.is_a?(Array)
where("username_lower ~* ?", "(#{filter.join("|")})")
else
where("username_lower ILIKE ?", "%#{filter}%")
end
}
end
scope :filter_by_username_or_email,
->(filter) {
->(filter) do
if filter.is_a?(String) && filter =~ /.+@.+/
# probably an email so try the bypass
if user_id = UserEmail.where("lower(email) = ?", filter.downcase).pick(:user_id)
@ -311,10 +311,10 @@ class User < ActiveRecord::Base
filter: "%#{filter}%",
)
end
}
end
scope :watching_topic,
->(topic) {
->(topic) do
joins(
DB.sql_fragment(
"LEFT JOIN category_users ON category_users.user_id = users.id AND category_users.category_id = :category_id",
@ -333,7 +333,7 @@ class User < ActiveRecord::Base
.where(
"category_users.notification_level > 0 OR topic_users.notification_level > 0 OR tag_users.notification_level > 0",
)
}
end
module NewTopicDuration
ALWAYS = -1

View File

@ -10,15 +10,15 @@ class UserBadge < ActiveRecord::Base
BOOLEAN_ATTRIBUTES = %w[is_favorite]
scope :grouped_with_count,
-> {
-> do
group(:badge_id, :user_id)
.select_for_grouping
.order("MAX(featured_rank) ASC")
.includes(:user, :granted_by, { badge: :badge_type }, post: :topic)
}
end
scope :select_for_grouping,
-> {
-> do
select(
UserBadge.attribute_names.map do |name|
operation = BOOLEAN_ATTRIBUTES.include?(name) ? "BOOL_OR" : "MAX"
@ -26,7 +26,7 @@ class UserBadge < ActiveRecord::Base
end,
'COUNT(*) AS "count"',
)
}
end
scope :for_enabled_badges,
-> { where("user_badges.badge_id IN (SELECT id FROM badges WHERE enabled)") }

View File

@ -4,11 +4,11 @@ class UserCustomField < ActiveRecord::Base
belongs_to :user
scope :searchable,
-> {
-> do
joins(
"INNER JOIN user_fields ON user_fields.id = REPLACE(user_custom_fields.name, 'user_field_', '')::INTEGER AND user_fields.searchable IS TRUE AND user_custom_fields.name like 'user_field_%'",
)
}
end
end
# == Schema Information

View File

@ -27,12 +27,12 @@ class WatchedWord < ActiveRecord::Base
after_destroy -> { WordWatcher.clear_cache! }
scope :for,
->(word:) {
->(word:) do
where(
"(word ILIKE :word AND case_sensitive = 'f') OR (word LIKE :word AND case_sensitive = 't')",
word: word,
)
}
end
def self.actions
@actions ||=

View File

@ -48,17 +48,17 @@ module Chat
before_validation :generate_auto_slug
scope :with_categories,
-> {
-> do
joins(
"LEFT JOIN categories ON categories.id = chat_channels.chatable_id AND chat_channels.chatable_type = 'Category'",
)
}
end
scope :public_channels,
-> {
-> do
with_categories.where(chatable_type: public_channel_chatable_types).where(
"categories.id IS NOT NULL",
)
}
end
delegate :empty?, to: :chat_messages, prefix: true

View File

@ -30,11 +30,11 @@ module Chat
dependent: :destroy,
foreign_key: :chat_message_id
has_many :bookmarks,
-> {
-> do
unscope(where: :bookmarkable_type).where(
bookmarkable_type: Chat::Message.polymorphic_name,
)
},
end,
as: :bookmarkable,
dependent: :destroy
has_many :upload_references,
@ -53,21 +53,21 @@ module Chat
foreign_key: :chat_message_id
scope :in_public_channel,
-> {
-> do
joins(:chat_channel).where(
chat_channel: {
chatable_type: Chat::Channel.public_channel_chatable_types,
},
)
}
end
scope :in_dm_channel,
-> {
-> do
joins(:chat_channel).where(
chat_channel: {
chatable_type: Chat::Channel.direct_channel_chatable_types,
},
)
}
end
scope :created_before, ->(date) { where("chat_messages.created_at < ?", date) }
scope :uncooked, -> { where("cooked_version <> ? or cooked_version IS NULL", BAKED_VERSION) }

View File

@ -17,11 +17,11 @@ module Chat
class_name: "Chat::Message"
has_many :chat_messages,
-> {
-> do
where("deleted_at IS NULL").order(
"chat_messages.created_at ASC, chat_messages.id ASC",
)
},
end,
foreign_key: :thread_id,
primary_key: :id,
class_name: "Chat::Message"

View File

@ -25,27 +25,27 @@ RSpec.describe BackupRestore::S3BackupStore do
@s3_client.stub_responses(
:list_objects_v2,
->(context) {
->(context) do
check_context(context)
{ contents: objects_with_prefix(context) }
},
end,
)
@s3_client.stub_responses(
:delete_object,
->(context) {
->(context) do
check_context(context)
expect do @objects.delete_if { |obj| obj[:key] == context.params[:key] } end.to change {
@objects
}
},
end,
)
@s3_client.stub_responses(
:head_object,
->(context) {
->(context) do
check_context(context)
if object = @objects.find { |obj| obj[:key] == context.params[:key] }
@ -53,12 +53,12 @@ RSpec.describe BackupRestore::S3BackupStore do
else
{ status_code: 404, headers: {}, body: "" }
end
},
end,
)
@s3_client.stub_responses(
:get_object,
->(context) {
->(context) do
check_context(context)
if object = @objects.find { |obj| obj[:key] == context.params[:key] }
@ -66,12 +66,12 @@ RSpec.describe BackupRestore::S3BackupStore do
else
{ status_code: 404, headers: {}, body: "" }
end
},
end,
)
@s3_client.stub_responses(
:put_object,
->(context) {
->(context) do
check_context(context)
@objects << {
@ -79,7 +79,7 @@ RSpec.describe BackupRestore::S3BackupStore do
size: context.params[:body].size,
last_modified: Time.zone.now,
}
},
end,
)
SiteSetting.s3_backup_bucket = "s3-backup-bucket"

View File

@ -130,9 +130,9 @@ RSpec.describe InlineOneboxer do
topic = Fabricate(:topic, title: "Inline oneboxer")
Fabricate(:post, topic: topic) # OP
Fabricate(:post, topic: topic)
lookup = ->(number) {
lookup = ->(number) do
InlineOneboxer.lookup("#{topic.url}/#{number}", skip_cache: true)[:title]
}
end
posts = topic.reload.posts.order("post_number ASC")
expect(lookup.call(0)).to eq("Inline oneboxer")

View File

@ -667,10 +667,10 @@ RSpec.describe Middleware::RequestTracker do
end
let(:logger) do
->(env, data) {
->(env, data) do
@env = env
@data = data
}
end
end
before { Middleware::RequestTracker.register_detailed_request_logger(logger) }

View File

@ -382,9 +382,9 @@ RSpec.describe NewPostManager do
result
end
@queue_handler = ->(manager) {
@queue_handler = ->(manager) do
manager.args[:raw] =~ /queue me/ ? manager.enqueue("default") : nil
}
end
NewPostManager.add_handler(&@counter_handler)
NewPostManager.add_handler(&@queue_handler)

View File

@ -771,12 +771,12 @@ RSpec.describe Plugin::Instance do
to: Notification.types[:code_review_commit_approved],
threshold: 1,
consolidation_window: 1.minute,
unconsolidated_query_blk: ->(notifications, _data) {
unconsolidated_query_blk: ->(notifications, _data) do
notifications.where("(data::json ->> 'consolidated') IS NULL")
},
consolidated_query_blk: ->(notifications, _data) {
end,
consolidated_query_blk: ->(notifications, _data) do
notifications.where("(data::json ->> 'consolidated') IS NOT NULL")
},
end,
).set_mutations(
set_data_blk: ->(notification) { notification.data_hash.merge(consolidated: true) },
)

View File

@ -391,11 +391,11 @@ RSpec.describe PostDestroyer do
user_stat = post2.user.user_stat
called = 0
topic_destroyed = ->(topic, user) {
topic_destroyed = ->(topic, user) do
expect(topic).to eq(post2.topic)
expect(user).to eq(post2.user)
called += 1
}
end
DiscourseEvent.on(:topic_destroyed, &topic_destroyed)
@ -414,11 +414,11 @@ RSpec.describe PostDestroyer do
expect(user_stat.reload.topic_count).to eq(1)
called = 0
topic_recovered = ->(topic, user) {
topic_recovered = ->(topic, user) do
expect(topic).to eq(post2.topic)
expect(user).to eq(post2.user)
called += 1
}
end
DiscourseEvent.on(:topic_recovered, &topic_recovered)

View File

@ -16,7 +16,7 @@ RSpec.describe "S3Inventory" do
client.stub_responses(
:list_objects,
->(context) {
->(context) do
expect(context.params[:prefix]).to eq(
"#{S3Inventory::INVENTORY_PREFIX}/#{S3Inventory::INVENTORY_VERSION}/bucket/original/hive",
)
@ -48,7 +48,7 @@ RSpec.describe "S3Inventory" do
],
next_marker: "eyJNYXJrZXIiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyfQ==",
}
},
end,
)
inventory.stubs(:cleanup!)

View File

@ -206,14 +206,14 @@ RSpec.describe Report do
if arg == :flag
user = Fabricate(:user)
topic = Fabricate(:topic, user: user)
builder = ->(dt) {
builder = ->(dt) do
PostActionCreator.create(
user,
Fabricate(:post, topic: topic, user: user),
:spam,
created_at: dt,
)
}
end
elsif arg == :signup
builder = ->(dt) { Fabricate(:user, created_at: dt) }
else

View File

@ -590,10 +590,10 @@ RSpec.describe TopicUser do
called = 0
visits = []
user_first_visit = ->(topic_id, user_id) {
user_first_visit = ->(topic_id, user_id) do
visits << "#{topic_id}-#{user_id}"
called += 1
}
end
DiscourseEvent.on(:topic_first_visited_by_user, &user_first_visit)

View File

@ -309,11 +309,11 @@ RSpec.describe TopicsController do
begin
called = false
assert = ->(original_topic, destination_topic) {
assert = ->(original_topic, destination_topic) do
called = true
expect(original_topic).to eq(topic)
expect(destination_topic).to eq(dest_topic)
}
end
DiscourseEvent.on(:topic_merged, &assert)

View File

@ -70,10 +70,10 @@ RSpec.describe UserSilencer do
context "with a plugin hook" do
before do
@override_silence_message = ->(opts) {
@override_silence_message = ->(opts) do
opts[:silence_message_params][:message_title] = "override title"
opts[:silence_message_params][:message_raw] = "override raw"
}
end
DiscourseEvent.on(:user_silenced, &@override_silence_message)
end