Skip to content

Commit

Permalink
feat: purge outdated graph data
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 17, 2024
1 parent 99e9702 commit 0043b7f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/workers/fiber_graph_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ class FiberGraphDetectWorker
include Sidekiq::Worker
sidekiq_options queue: "fiber"

attr_accessor :graph_node_ids, :graph_channel_outpoint

def perform
@graph_node_ids = []
@graph_channel_outpoints = []

# sync graph nodes and channels
["nodes", "channels"].each { fetch_graph_infos(_1) }
# purge outdated graph nodes
FiberGraphNode.where.not(node_id: @graph_node_ids).delete_all
# purge outdated graph channels
FiberGraphChannel.where.not(channel_outpoint: @graph_channel_outpoints).delete_all

# check channel is closed
FiberGraphChannel.open_channels.each do |channel|
Expand Down Expand Up @@ -61,7 +70,7 @@ def upsert_node_with_cfg_info(node)
peer_id: extract_peer_id(node["addresses"]),
auto_accept_min_ckb_funding_amount: node["auto_accept_min_ckb_funding_amount"],
}

@graph_node_ids << node_attributes[:node_id]
fiber_graph_node = FiberGraphNode.upsert(node_attributes, unique_by: %i[node_id], returning: %i[id])

return unless fiber_graph_node && node["udt_cfg_infos"].present?
Expand All @@ -87,6 +96,7 @@ def build_channel_attributes(channel)

channel_outpoint = channel["channel_outpoint"]
open_transaction = CkbTransaction.find_by(tx_hash: channel_outpoint[0..65])
@graph_channel_outpoints << channel_outpoint

{
channel_outpoint:,
Expand Down

0 comments on commit 0043b7f

Please sign in to comment.