lib/eco/api/microcases/people_search.rb in eco-helpers-1.5.14 vs lib/eco/api/microcases/people_search.rb in eco-helpers-1.5.15

- old
+ new

@@ -9,27 +9,52 @@ # @param options [Hash] the options. # @param silent [Boolean] `false` if low level search messages should be shown. # @return [Eco::API::Organization::People] the `People` object with the found persons. def people_search(data, options: {}, silent: true) session.logger.info("Going to api get #{data.length} entries...") - status = session.batch.search(data, silent: silent) - people = Eco::API::Organization::People.new(status.people) - session.logger.info("... could get #{people.length} people (out of #{data.length} entries)") + start = Time.now + people = session.batch.search(data, silent: silent).yield_self do |status| + secs = Time.now - start + Eco::API::Organization::People.new(status.people).tap do |people| + cnt = people.count + per_sec = (cnt.to_f / secs).floor + msg = "... could get #{cnt} people (out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)" + session.logger.info(msg) + end + end + # get the supervisors of found people (current supervisors) supers = people_search_prepare_supers_request(people) if supers.length > 0 session.logger.info(" Going to api get #{supers.length} current supervisors...") - status = session.batch.search(supers, silent: silent) - people = people.merge(status.people, strict: micro.strict_search?(options)) + start = Time.now + people = session.batch.search(supers, silent: silent).yield_self do |status| + secs = Time.now - start + found = status.people + cnt = found.count + per_sec = (cnt.to_f / secs).floor + msg = "... could find #{cnt} current supers (out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)" + session.logger.info(msg) + people.merge(found, strict: micro.strict_search?(options)) + end end # get the supervisors referred in the input data (future supervisors) supers = people_search_prepare_supers_request(data, people) if supers.length > 0 - session.logger.info(" Going to api get #{supers.length} supervisors as per entries...") - status = session.batch.search(supers, silent: silent) - people = people.merge(status.people, strict: micro.strict_search?(options)) + session.logger.info(" Going to api get #{supers.length} supervisors as per input entries...") + start = Time.now + + people = session.batch.search(supers, silent: silent).yield_self do |status| + secs = Time.now - start + found = status.people + cnt = found.count + per_sec = (cnt.to_f / secs).floor + msg = "... could find #{cnt} input supers (out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)" + session.logger.info(msg) + people.merge(found, strict: micro.strict_search?(options)) + end end session.logger.info("Finally got #{people.length} people (out of #{data.length} entries)") people end