Skip to content

Commit dcf4613

Browse files
committed
Adjust backfill requests to latest spec
1 parent d9a1e1a commit dcf4613

File tree

9 files changed

+69
-23
lines changed

9 files changed

+69
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This migration comes from fasp_data_sharing (originally 20250103141700)
2+
class ReplaceCursorWithFulfilledFlag < ActiveRecord::Migration[8.0]
3+
def change
4+
remove_column :fasp_data_sharing_backfill_requests, :cursor, :string
5+
add_column :fasp_data_sharing_backfill_requests, :fulfilled, :boolean, null: false, default: false
6+
end
7+
end

debug_fasp/db/schema.rb

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fasp_base/lib/fasp_base/integration_test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def response_authentication_headers(server, status, body)
2020
headers.merge(signature.to_h)
2121
end
2222

23-
def stub_request_to(server, method, path, response_status, response_body)
23+
def stub_request_to(server, method, path, response_status, response_body = "")
2424
response_body = encode_body(response_body)
2525
response_headers = {
2626
"content-type" => "application/json"

fasp_data_sharing/app/models/fasp_data_sharing/backfill_request.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@ class BackfillRequest < ApplicationRecord
99
validates :max_count, numericality: { only_integer: true }
1010

1111
class << self
12-
def make(server, category:, max_count: 100, cursor: nil)
12+
def make(server, category:, max_count: 100)
1313
response = FaspBase::Request.new(server)
1414
.post("/data_sharing/v0/backfill_requests", body: {
1515
category:,
16-
maxCount: max_count,
17-
cursor:
16+
maxCount: max_count
1817
}.compact
1918
)
2019

2120
remote_id = response["backfillRequest"]["id"]
2221
create!(
2322
fasp_base_server: server, remote_id:, category:,
24-
max_count:, cursor:
23+
max_count:
2524
)
2625
end
2726
end
27+
28+
def continue!
29+
response = FaspBase::Request.new(fasp_base_server)
30+
.post("/data_sharing/v0/backfill_requests/#{remote_id}/continuation")
31+
end
32+
33+
def mark_as_fulfilled!
34+
update!(fulfilled: true)
35+
end
2836
end
2937
end

fasp_data_sharing/app/models/fasp_data_sharing/event.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class FaspDataSharing::Event
3030
attribute :source
3131
attribute :category, :string
3232
attribute :event_type, :string
33-
attribute :cursor, :string
3433
attribute :more_objects_available, :boolean
3534
attribute :object_uris
3635

@@ -56,8 +55,7 @@ def process
5655
def update_backfill_request
5756
return unless backfill_event?
5857

59-
@source_record.update(cursor:) if cursor
60-
@source_record.destroy if more_objects_available == false
58+
@source_record.mark_as_fulfilled! unless more_objects_available
6159
end
6260

6361
def source_is_known
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ReplaceCursorWithFulfilledFlag < ActiveRecord::Migration[8.0]
2+
def change
3+
remove_column :fasp_data_sharing_backfill_requests, :cursor, :string
4+
add_column :fasp_data_sharing_backfill_requests, :fulfilled, :boolean, null: false, default: false
5+
end
6+
end

fasp_data_sharing/test/dummy/db/schema.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2024_12_11_140048) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_01_03_141700) do
1414
create_table "fasp_base_servers", force: :cascade do |t|
1515
t.string "base_url", null: false
1616
t.integer "user_id", null: false
@@ -20,16 +20,16 @@
2020
t.string "fasp_remote_id"
2121
t.string "public_key_pem"
2222
t.string "registration_completion_uri"
23-
t.index [ "base_url" ], name: "index_fasp_base_servers_on_base_url", unique: true
24-
t.index [ "user_id" ], name: "index_fasp_base_servers_on_user_id"
23+
t.index ["base_url"], name: "index_fasp_base_servers_on_base_url", unique: true
24+
t.index ["user_id"], name: "index_fasp_base_servers_on_user_id"
2525
end
2626

2727
create_table "fasp_base_users", force: :cascade do |t|
2828
t.string "email", null: false
2929
t.string "password_digest"
3030
t.datetime "created_at", null: false
3131
t.datetime "updated_at", null: false
32-
t.index [ "email" ], name: "index_fasp_base_users_on_email", unique: true
32+
t.index ["email"], name: "index_fasp_base_users_on_email", unique: true
3333
end
3434

3535
create_table "fasp_data_sharing_actors", force: :cascade do |t|
@@ -43,10 +43,10 @@
4343
t.string "remote_id", null: false
4444
t.string "category", null: false
4545
t.integer "max_count"
46-
t.string "cursor"
4746
t.datetime "created_at", null: false
4847
t.datetime "updated_at", null: false
49-
t.index [ "fasp_base_server_id" ], name: "idx_on_fasp_base_server_id_0f3fe7f51e"
48+
t.boolean "fulfilled", default: false, null: false
49+
t.index ["fasp_base_server_id"], name: "idx_on_fasp_base_server_id_0f3fe7f51e"
5050
end
5151

5252
create_table "fasp_data_sharing_subscriptions", force: :cascade do |t|
@@ -61,7 +61,7 @@
6161
t.integer "threshold_replies"
6262
t.datetime "created_at", null: false
6363
t.datetime "updated_at", null: false
64-
t.index [ "fasp_base_server_id" ], name: "index_fasp_data_sharing_subscriptions_on_fasp_base_server_id"
64+
t.index ["fasp_base_server_id"], name: "index_fasp_data_sharing_subscriptions_on_fasp_base_server_id"
6565
end
6666

6767
add_foreign_key "fasp_base_servers", "fasp_base_users", column: "user_id"

fasp_data_sharing/test/integration/announcements_test.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class ActorTest < ActionDispatch::IntegrationTest
3+
class AnnouncementsTest < ActionDispatch::IntegrationTest
44
include FaspBase::IntegrationTestHelper
55

66
setup do
@@ -81,7 +81,7 @@ class ActorTest < ActionDispatch::IntegrationTest
8181
assert_response :success
8282
end
8383

84-
test "with a matching backfill request it enqueues jobs and updates the cursor" do
84+
test "with a matching backfill request it enqueues jobs" do
8585
backfill_request = fasp_data_sharing_backfill_requests(:accounts)
8686
payload = {
8787
source: {
@@ -90,7 +90,7 @@ class ActorTest < ActionDispatch::IntegrationTest
9090
}
9191
},
9292
category: "account",
93-
cursor: "efgh",
93+
moreObjectsAvailable: true,
9494
objectUris: [
9595
"https://fediverse-server.example.com/@example/2342",
9696
"https://fediverse-server.example.com/@other/8726"
@@ -104,11 +104,10 @@ class ActorTest < ActionDispatch::IntegrationTest
104104
end
105105

106106
assert_response :success
107-
assert_equal "efgh", backfill_request.reload.cursor
108107
end
109108

110109

111-
test "with a matching backfill request and no more objects to get it deletes the backfill request" do
110+
test "with a matching backfill request and no more objects to get it marks the backfill request as fulfilled" do
112111
backfill_request = fasp_data_sharing_backfill_requests(:accounts)
113112
payload = {
114113
source: {
@@ -127,9 +126,11 @@ class ActorTest < ActionDispatch::IntegrationTest
127126
uri = fasp_data_sharing.fasp_data_sharing_v0_announcements_url
128127
headers = request_authentication_headers(@server, :post, uri, payload)
129128

130-
assert_difference -> { FaspDataSharing::BackfillRequest.count }, -1 do
129+
assert_changes -> { backfill_request.fulfilled? } do
131130
assert_enqueued_jobs 2, only: FaspDataSharing::ProcessAccountBackfillJob do
132131
post fasp_data_sharing.fasp_data_sharing_v0_announcements_path, as: :json, params: payload, headers: headers
132+
133+
backfill_request.reload
133134
end
134135
end
135136

fasp_data_sharing/test/models/fasp_data_sharing/backfill_request_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,31 @@ class BackfillRequestTest < ActiveSupport::TestCase
3232
assert_equal "account", backfill_request.category
3333
assert_equal 90, backfill_request.max_count
3434
end
35+
36+
test "continuing an existing backfill request" do
37+
stubbed_request = stub_request_to(@server, :post, "/data_sharing/v0/backfill_requests/672/continuation", 204)
38+
backfill_request = BackfillRequest.create(
39+
fasp_base_server: @server,
40+
remote_id: "672",
41+
category: "content",
42+
max_count: 100
43+
)
44+
backfill_request.continue!
45+
46+
assert_requested(stubbed_request)
47+
end
48+
49+
test "marking as fulfilled" do
50+
backfill_request = BackfillRequest.create(
51+
fasp_base_server: @server,
52+
remote_id: "672",
53+
category: "content",
54+
max_count: 100
55+
)
56+
57+
assert_changes -> { backfill_request.fulfilled? } do
58+
backfill_request.mark_as_fulfilled!
59+
end
60+
end
3561
end
3662
end

0 commit comments

Comments
 (0)