lib/zold/node/farm.rb in zold-0.23.7 vs lib/zold/node/farm.rb in zold-0.23.8

- old
+ new

@@ -151,11 +151,11 @@ private def cleanup(host, port, threads) scores = load before = scores.map(&:value).max.to_i - save(threads, [Score.new(host: host, port: port, invoice: @invoice, strength: @strength)]) + save(host, port, threads, [Score.new(host: host, port: port, invoice: @invoice, strength: @strength)]) scores = load free = scores.reject { |s| @threads.exists?(s.to_mnemo) } @pipeline << free[0] if @pipeline.size.zero? && !free.empty? after = scores.map(&:value).max.to_i return unless before != after && !after.zero? @@ -180,19 +180,22 @@ return unless s.strength >= @strength Thread.current.name = s.to_mnemo Thread.current.thread_variable_set(:start, Time.now.utc.iso8601) score = @farmer.up(s) @log.debug("New score discovered: #{score}") if @strength > 4 - save(threads, [score]) + save(host, port, threads, [score]) cleanup(host, port, threads) end - def save(threads, list = []) + def save(host, port, threads, list = []) scores = load + list period = @lifetime / [threads, 1].max body = scores.select(&:valid?) .reject(&:expired?) .reject { |s| s.strength < @strength } + .select { |s| s.host == host } + .select { |s| s.port == port } + .select { |s| s.invoice == @invoice } .sort_by(&:value) .reverse .uniq(&:time) .uniq { |s| (s.age / period).round } .map(&:to_s)