Limit number of relays to publish zap receipts to
This commit is contained in:
		
							parent
							
								
									2d1ff29eca
								
							
						
					
					
						commit
						48041630ca
					
				| @ -169,6 +169,9 @@ class Setting < RailsSettings::Base | |||||||
|   field :nostr_public_key, type: :string, |   field :nostr_public_key, type: :string, | ||||||
|     default: ENV["NOSTR_PUBLIC_KEY"].presence |     default: ENV["NOSTR_PUBLIC_KEY"].presence | ||||||
| 
 | 
 | ||||||
|  |   field :nostr_zaps_relay_limit, type: :integer, | ||||||
|  |     default: 12 | ||||||
|  | 
 | ||||||
|   # |   # | ||||||
|   # OpenCollective |   # OpenCollective | ||||||
|   # |   # | ||||||
|  | |||||||
| @ -7,8 +7,7 @@ module NostrManager | |||||||
|     def call |     def call | ||||||
|       tags = parse_tags(@zap.request_event.tags) |       tags = parse_tags(@zap.request_event.tags) | ||||||
| 
 | 
 | ||||||
|       # TODO limit to 15 or so relays |       tags[:relays].take(Setting.nostr_zaps_relay_limit).each do |relay_url| | ||||||
|       tags[:relays].each do |relay_url| |  | ||||||
|         if @delayed |         if @delayed | ||||||
|           NostrPublishEventJob.perform_later(event: @zap.receipt, relay: relay_url) |           NostrPublishEventJob.perform_later(event: @zap.receipt, relay: relay_url) | ||||||
|         else |         else | ||||||
|  | |||||||
| @ -19,5 +19,15 @@ | |||||||
|         title: "Public key", |         title: "Public key", | ||||||
|         description: "The corresponding public key of the accounts service" |         description: "The corresponding public key of the accounts service" | ||||||
|       ) %> |       ) %> | ||||||
| <% end %> |  | ||||||
| </ul> | </ul> | ||||||
|  | </section> | ||||||
|  | <section> | ||||||
|  | <h3>Zaps</h3> | ||||||
|  | <ul role="list"> | ||||||
|  |   <%= render FormElements::FieldsetResettableSettingComponent.new( | ||||||
|  |         key: :nostr_zaps_relay_limit, | ||||||
|  |         title: "Relay limit", | ||||||
|  |         description: "The maximum number of relays to publish zap receipts to" | ||||||
|  |       ) %> | ||||||
|  | </ul> | ||||||
|  | <% end %> | ||||||
|  | |||||||
| @ -6,11 +6,35 @@ RSpec.describe NostrManager::PublishZapReceipt, type: :model do | |||||||
| 
 | 
 | ||||||
|   describe "Default/delayed execution" do |   describe "Default/delayed execution" do | ||||||
|     it "publishes zap receipts to all requested relays" do |     it "publishes zap receipts to all requested relays" do | ||||||
|       2.times do |       expect(NostrPublishEventJob).to receive(:perform_later) | ||||||
|         expect(NostrPublishEventJob).to receive(:perform_later).and_return(true) |         .exactly(2).times.and_return(true) | ||||||
|  | 
 | ||||||
|  |       described_class.call(zap: zap) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |     context "with a long relay list" do | ||||||
|  |       before do | ||||||
|  |         relays = zap.request["tags"].find { |t| t.first == "relays" } | ||||||
|  |         [ | ||||||
|  |           "wss://aegonstargaryen.example.com", "wss://visenya.example.com", | ||||||
|  |           "wss://rhaenys.example.com", "wss://housevelaryon.example.com", | ||||||
|  |           "wss://aemond.example.com", "wss://jaehaerys.example.com", | ||||||
|  |           "wss://daenerys.example.com", "wss://corlys.example.com", | ||||||
|  |           "wss://laenor.example.com", "wss://alysanne.example.com", | ||||||
|  |           "wss://balerion.example.com", "wss://meraxes.example.com", | ||||||
|  |           "wss://vhaegar.example.com", "wss://vermax.example.com", | ||||||
|  |           "wss://caraxes.example.com" | ||||||
|  |         ].each do |url| | ||||||
|  |           relays << url | ||||||
|  |         end | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|  |       it "limits publishing attempts to the first 12 relays" do | ||||||
|  |         expect(NostrPublishEventJob).to receive(:perform_later) | ||||||
|  |           .exactly(12).times.and_return(true) | ||||||
|  | 
 | ||||||
|         described_class.call(zap: zap) |         described_class.call(zap: zap) | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  | end | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user