lib/eco/api/microcases/people_search.rb in eco-helpers-2.7.24 vs lib/eco/api/microcases/people_search.rb in eco-helpers-2.7.25

- old
+ new

@@ -8,63 +8,77 @@ # @param data [Eco::API::Organization::People, Enumerable<Person>, Enumerable<Hash>] # `People` to search against the server. # @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) # rubocop:disable Metrics/AbcSize - session.logger.info("Going to api get #{data.length} entries...") + def people_search(data, options: {}, silent: true) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + log(:info) { "Going to api get #{data.length} entries..." } - silent = silent && data.count <= 500 + silent &&= data.count <= 500 start = Time.now people = session.batch.search(data, silent: silent).then do |status| secs = (Time.now - start).round(3) + Eco::API::Organization::People.new(status.people).tap do |people| # rubocop:disable Lint/ShadowingOuterLocalVariable cnt = people.count per_sec = (cnt.to_f / secs).round(2) + msg = "... could get #{cnt} people " msg << "(out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)" - session.logger.info(msg) + + log(:info) { msg } end end # get the supervisors of found people (current supervisors) supers = people_search_prepare_supers_request(people) if supers.length.positive? - session.logger.info(" Going to api get #{supers.length} current supervisors...") + log(:info) { + " Going to api get #{supers.length} current supervisors..." + } + start = Time.now people = session.batch.search(supers, silent: silent).then do |status| secs = (Time.now - start).round(3) found = status.people cnt = found.count per_sec = (cnt.to_f / secs).round(2) + msg = "... could find #{cnt} current supers " msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)" - session.logger.info(msg) + log(: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.positive? - session.logger.info(" Going to api get #{supers.length} supervisors as per input entries...") - start = Time.now + log(:info) { + " Going to api get #{supers.length} supervisors as per input entries..." + } + start = Time.now people = session.batch.search(supers, silent: silent).then do |status| secs = (Time.now - start).round(3) found = status.people cnt = found.count per_sec = (cnt.to_f / secs).round(2) + msg = "... could find #{cnt} input supers " msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)" - session.logger.info(msg) + log(: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)") + log(:info) { + "Finally got #{people.length} people (out of #{data.length} entries)" + } + people end private