# התייעצות כיצד להשיג מידע משתמשים

**URL:** <https://meta.discourse.org/t/consultation-on-how-to-obtain-user-information/242465>\
**Category:** Development\
**Created:** [20 באוקטובר,‏ 2022,‏ 10:34am UTC](https://meta.discourse.org/t/consultation-on-how-to-obtain-user-information/242465 "2022-10-20T10:34:05Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Programer-D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/programer-d/32/215194_2.png) [@Programer-D](https://meta.discourse.org/u/Programer-D)\
**Post date:** [20 באוקטובר,‏ 2022,‏ 10:34am UTC](https://meta.discourse.org/t/consultation-on-how-to-obtain-user-information/242465/1 "2022-10-20T10:34:05Z")

</div>

I have created a form as a plugin that searches for a user from a user field that I have defined independently.

I used Web API to store user information in an external DB (AWS DynamoDB) and extract data from it for searching.

```ruby
class DiscourseUserSearchController < ApplicationController
  def index
  end

  def search
    dynamodb = Aws::DynamoDB::Client.new(
      access_key_id: ENV['ACCESS_KEY_ID'],
      secret_access_key: ENV['SECRET_ACCESS_KEY'],
      region: AWS_REGION
    )

    scan_condition = {
      table_name: "DiscourseUserInformation"
    }
    result = dynamodb.scan(scan_condition)

    result = result.items
    Rails.logger.info result
    data = result.map do |user_data|
      user = User.find(user_data['UserID'])
      user_data['avatar_template'] = user.avatar_template
      user_data['username'] = user.username
      next user_data

    end

    render status: 200, json: { status: 200, data: data }
  end
end

```

The above code gets all users when the page is opened and passes them to angular.

This works fine, but the response takes 3500 milliseconds, which is not very desirable. (about 1400 search users).

I think the problem is that I am doing User.find(user\_data[‘UserID’]) in a loop, but I can’t think of a way to make it better.

I would like to display user cards, so I think it is necessary to acquire users on Ruby, but I would be happy to get suggestions on how to make it faster.

---

_[View the full topic](https://meta.discourse.org/t/consultation-on-how-to-obtain-user-information/242465)._
