# header_file_size :integer
# header_updated_at :datetime
# avatar_remote_url :string
-# subscription_expires_at :datetime
# locked :boolean default(FALSE), not null
# header_remote_url :string default(""), not null
# last_webfingered_at :datetime
#
class Account < ApplicationRecord
+ self.ignored_columns = %w(subscription_expires_at)
+
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[a-z0-9]+)?)/i
scope :remote, -> { where.not(domain: nil) }
scope :local, -> { where(domain: nil) }
- scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :silenced, -> { where.not(silenced_at: nil) }
scope :suspended, -> { where.not(suspended_at: nil) }
"acct:#{local_username_and_domain}"
end
- def subscribed?
- subscription_expires_at.present?
- end
-
def searchable?
!(suspended? || moved?)
end
--- /dev/null
+class RemoveSubscriptionExpiresAtFromAccounts < ActiveRecord::Migration[5.0]
+ def change
+ safety_assured do
+ remove_column :accounts, :subscription_expires_at, :datetime, null: true, default: nil
+ end
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_02_21_045109) do
+ActiveRecord::Schema.define(version: 2021_03_08_133107) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.integer "header_file_size"
t.datetime "header_updated_at"
t.string "avatar_remote_url"
- t.datetime "subscription_expires_at"
t.boolean "locked", default: false, null: false
t.string "header_remote_url", default: "", null: false
t.datetime "last_webfingered_at"
end
end
- describe '#subscribed?' do
- it 'returns false when no subscription expiration information is present' do
- account = Fabricate(:account, subscription_expires_at: nil)
- expect(account.subscribed?).to be false
- end
-
- it 'returns true when subscription expiration has been set' do
- account = Fabricate(:account, subscription_expires_at: 30.days.from_now)
- expect(account.subscribed?).to be true
- end
- end
-
describe '#possibly_stale?' do
let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) }
end
end
- describe 'expiring' do
- it 'returns remote accounts with followers whose subscription expiration date is past or not given' do
- local = Fabricate(:account, domain: nil)
- matches = [
- { domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' },
- ].map(&method(:Fabricate).curry(2).call(:account))
- matches.each(&local.method(:follow!))
- Fabricate(:account, domain: 'remote', subscription_expires_at: nil)
- local.follow!(Fabricate(:account, domain: 'remote', subscription_expires_at: '2000-01-03T00:00:00Z'))
- local.follow!(Fabricate(:account, domain: nil, subscription_expires_at: nil))
-
- expect(Account.expiring('2000-01-02T00:00:00Z').recent).to eq matches.reverse
- end
- end
-
describe 'remote' do
it 'returns an array of accounts who have a domain' do
account_1 = Fabricate(:account, domain: nil)