Add support for FASP data sharing (#34415)
This commit is contained in:
parent
3ea1f074ab
commit
a5a2c6dc7e
38 changed files with 1140 additions and 1 deletions
67
app/models/fasp/backfill_request.rb
Normal file
67
app/models/fasp/backfill_request.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: fasp_backfill_requests
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# category :string not null
|
||||
# cursor :string
|
||||
# fulfilled :boolean default(FALSE), not null
|
||||
# max_count :integer default(100), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# fasp_provider_id :bigint(8) not null
|
||||
#
|
||||
class Fasp::BackfillRequest < ApplicationRecord
|
||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
||||
|
||||
validates :category, presence: true, inclusion: Fasp::DATA_CATEGORIES
|
||||
validates :max_count, presence: true,
|
||||
numericality: { only_integer: true }
|
||||
|
||||
after_commit :queue_fulfillment_job, on: :create
|
||||
|
||||
def next_objects
|
||||
@next_objects ||= base_scope.to_a
|
||||
end
|
||||
|
||||
def next_uris
|
||||
next_objects.map { |o| ActivityPub::TagManager.instance.uri_for(o) }
|
||||
end
|
||||
|
||||
def more_objects_available?
|
||||
return false if next_objects.empty?
|
||||
|
||||
base_scope.where(id: ...(next_objects.last.id)).any?
|
||||
end
|
||||
|
||||
def advance!
|
||||
if more_objects_available?
|
||||
update!(cursor: next_objects.last.id)
|
||||
else
|
||||
update!(fulfilled: true)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def base_scope
|
||||
result = category_scope.limit(max_count).order(id: :desc)
|
||||
result = result.where(id: ...cursor) if cursor.present?
|
||||
result
|
||||
end
|
||||
|
||||
def category_scope
|
||||
case category
|
||||
when 'account'
|
||||
Account.discoverable.without_instance_actor
|
||||
when 'content'
|
||||
Status.indexable
|
||||
end
|
||||
end
|
||||
|
||||
def queue_fulfillment_job
|
||||
Fasp::BackfillWorker.perform_async(id)
|
||||
end
|
||||
end
|
|
@ -22,7 +22,9 @@
|
|||
class Fasp::Provider < ApplicationRecord
|
||||
include DebugConcern
|
||||
|
||||
has_many :fasp_backfill_requests, inverse_of: :fasp_provider, class_name: 'Fasp::BackfillRequest', dependent: :delete_all
|
||||
has_many :fasp_debug_callbacks, inverse_of: :fasp_provider, class_name: 'Fasp::DebugCallback', dependent: :delete_all
|
||||
has_many :fasp_subscriptions, inverse_of: :fasp_provider, class_name: 'Fasp::Subscription', dependent: :delete_all
|
||||
|
||||
validates :name, presence: true
|
||||
validates :base_url, presence: true, url: true
|
||||
|
|
43
app/models/fasp/subscription.rb
Normal file
43
app/models/fasp/subscription.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: fasp_subscriptions
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# category :string not null
|
||||
# max_batch_size :integer not null
|
||||
# subscription_type :string not null
|
||||
# threshold_likes :integer
|
||||
# threshold_replies :integer
|
||||
# threshold_shares :integer
|
||||
# threshold_timeframe :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# fasp_provider_id :bigint(8) not null
|
||||
#
|
||||
class Fasp::Subscription < ApplicationRecord
|
||||
TYPES = %w(lifecycle trends).freeze
|
||||
|
||||
belongs_to :fasp_provider, class_name: 'Fasp::Provider'
|
||||
|
||||
validates :category, presence: true, inclusion: Fasp::DATA_CATEGORIES
|
||||
validates :subscription_type, presence: true,
|
||||
inclusion: TYPES
|
||||
|
||||
scope :category_content, -> { where(category: 'content') }
|
||||
scope :category_account, -> { where(category: 'account') }
|
||||
scope :lifecycle, -> { where(subscription_type: 'lifecycle') }
|
||||
scope :trends, -> { where(subscription_type: 'trends') }
|
||||
|
||||
def threshold=(threshold)
|
||||
self.threshold_timeframe = threshold['timeframe'] || 15
|
||||
self.threshold_shares = threshold['shares'] || 3
|
||||
self.threshold_likes = threshold['likes'] || 3
|
||||
self.threshold_replies = threshold['replies'] || 3
|
||||
end
|
||||
|
||||
def timeframe_start
|
||||
threshold_timeframe.minutes.ago
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue