Fix nostr event fetching issues
This commit is contained in:
@@ -34,7 +34,9 @@ module NostrManager
|
||||
received_event.signal
|
||||
end
|
||||
elsif msg && msg[0] == "EOSE"
|
||||
Thread.current.exit
|
||||
mutex.synchronize do
|
||||
received_event.signal
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ module NostrManager
|
||||
end
|
||||
|
||||
def call
|
||||
received_events = 0
|
||||
events = []
|
||||
|
||||
begin
|
||||
@@ -17,28 +16,17 @@ module NostrManager
|
||||
@relays.each do |url|
|
||||
event = NostrManager::FetchEvent.call(filter: @filter, relay_url: url)
|
||||
|
||||
if event.present?
|
||||
events << event if events.none? { |e| e["id"] == event["id"] }
|
||||
received_events += 1
|
||||
end
|
||||
|
||||
if received_events >= @max_events
|
||||
Rails.logger.debug "Found #{@max_events} events, ending the search"
|
||||
break
|
||||
if event.present? && events.none? { |e| e["id"] == event["id"] }
|
||||
events << event
|
||||
break if events.size >= @max_events
|
||||
end
|
||||
end
|
||||
|
||||
events.min_by { |e| e["created_at"] }
|
||||
end
|
||||
rescue Timeout::Error
|
||||
if events.size == 1
|
||||
Rails.logger.debug "[nostr] Timeout: only found 1 event within #{TIMEOUT} seconds for filter: #{@filter.inspect}"
|
||||
events.first
|
||||
else
|
||||
Rails.logger.debug "[nostr] Timeout: no events found within #{TIMEOUT} seconds for filter: #{@filter.inspect}"
|
||||
nil
|
||||
end
|
||||
Rails.logger.debug "[nostr] Timeout after #{TIMEOUT}s, found #{events.size} events"
|
||||
end
|
||||
|
||||
events.max_by { |e| e["created_at"] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user