Skip to content

Commit fa3cc5f

Browse files
committed
Add backfill request support to debug provider
1 parent dcf4613 commit fa3cc5f

File tree

17 files changed

+195
-22
lines changed

17 files changed

+195
-22
lines changed

debug_fasp/app/controllers/accounts_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def destroy
1414
redirect_to accounts_path, notice: t(".success")
1515
end
1616

17+
def destroy_all
18+
Account.delete_all
19+
20+
redirect_to contents_path, notice: t(".success")
21+
end
22+
1723
private
1824

1925
def load_account

debug_fasp/app/controllers/application_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ class ApplicationController < ActionController::Base
33

44
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
55
allow_browser versions: :modern
6+
7+
private
8+
9+
def current_server
10+
@current_server ||= current_user&.servers&.first
11+
end
612
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class BackfillRequestsController < ApplicationController
2+
helper_method :current_server
3+
4+
before_action :load_backfill_request, only: [ :update, :destroy ]
5+
6+
def index
7+
@backfill_requests = FaspDataSharing::BackfillRequest
8+
.where(fasp_base_server: current_server).all
9+
end
10+
11+
def create
12+
create_backfill_request
13+
14+
redirect_to backfill_requests_path, notice: t(".success")
15+
end
16+
17+
def update
18+
@backfill_request.continue!
19+
20+
redirect_to backfill_requests_path, notice: t(".success")
21+
end
22+
23+
def destroy
24+
@backfill_request.destroy
25+
26+
redirect_to backfill_requests_path, notice: t(".success")
27+
end
28+
29+
private
30+
31+
def load_backfill_request
32+
@backfill_request = FaspDataSharing::BackfillRequest
33+
.where(fasp_base_server_id: current_user.server_ids)
34+
.find(params[:id])
35+
end
36+
37+
def create_backfill_request
38+
case params[:type]
39+
when "content"
40+
FaspDataSharing::BackfillRequest.make(current_server, category: "content", max_count: 5)
41+
when "account"
42+
FaspDataSharing::BackfillRequest.make(current_server, category: "account", max_count: 5)
43+
end
44+
end
45+
end

debug_fasp/app/controllers/contents_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def destroy
1414
redirect_to contents_path, notice: t(".success")
1515
end
1616

17+
def destroy_all
18+
TrendSignal.delete_all
19+
Content.delete_all
20+
21+
redirect_to contents_path, notice: t(".success")
22+
end
23+
1724
private
1825

1926
def load_content

debug_fasp/app/controllers/subscriptions_controller.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ def destroy
2121

2222
private
2323

24-
def current_server
25-
@current_server ||= current_user.servers.first
26-
end
27-
2824
def create_subscription
2925
case params[:type]
3026
when "content"

debug_fasp/app/controllers/trend_signals_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ def destroy
1111

1212
redirect_to trend_signals_path, notice: t(".success")
1313
end
14+
15+
def destroy_all
16+
TrendSignal.delete_all
17+
18+
redirect_to contents_path, notice: t(".success")
19+
end
1420
end

debug_fasp/app/helpers/application_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module ApplicationHelper
33

44
DATA_SHARING_TABS = {
55
subscriptions: :subscriptions_path,
6+
backfill_requests: :backfill_requests_path,
67
contents: :contents_path,
78
accounts: :accounts_path,
89
trend_signals: :trend_signals_path
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class FaspDataSharing::ProcessAccountBackfillJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
unless Account.where(uri:).exists?
6+
object = fetch_object(uri)
7+
Account.create!(
8+
uri: object["id"],
9+
object_type: object["type"],
10+
full_object: object
11+
)
12+
end
13+
end
14+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class FaspDataSharing::ProcessContentBackfillJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
unless Content.where(uri:).exists?
6+
object = fetch_object(uri)
7+
Content.create!(
8+
uri: object["id"],
9+
object_type: object["type"],
10+
full_object: object
11+
)
12+
end
13+
end
14+
end

debug_fasp/app/views/accounts/index.html.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<%= render "shared/data_sharing_tabs", active: :accounts %>
22

3-
<%= page_header do %>
4-
<%= t(".accounts") %>
5-
<% end %>
3+
<div class="flex justify-between items-center">
4+
<%= page_header do %>
5+
<%= t(".accounts") %>
6+
<% end %>
7+
<%= button_link_to t(".destroy_all"), accounts_path, data: {turbo_confirm: t('are_you_sure'), turbo_method: :delete} %>
8+
</div>
69

710
<table>
811
<thead>

0 commit comments

Comments
 (0)