From a performance perspective, what common rules should be applied to such a database schema?
Golang
What to do if we have added all the necessary indexes, but the database still cannot handle the load and slows down?
Why do Go developers not guarantee the order of map traversal during range?
// GetUsersList returns a list of users. (approximately 1 million users are stored in the database) // Used to display the list of users in the admin panel. If isActive = true, only active users are returned. func (u *UsersRepo) GetUsersList(ctx context.Context, isActive bool) ([]User, error) { rows, err := u.DB.Query("SELECT id, name, phone FROM users WHERE is_active = ?", isActive) if err != nil { return nil, errors.New("error fetching user list") } var users []User // Fill in user information. for rows.Next() { var user User err := rows.Scan(&user.ID, &user.Name, &user.Phone) if err != nil { return nil, err } // Get the user's email list err, err := u.DB.QueryContext(ctx, "SELECT email FROM user_emails WHERE user_id = ?", user.ID) if err != nil { return nil, errors.New("error fetching user emails") } var emails []string for er.Next() { var email string err := rows.Scan(&email) if err != nil { return nil, err } emails = append(emails, email) } if len(emails) != 0 { for i, e := range emails { emails[i] = strings.ToLower(e) } } user.Emails = emails // Get profile information from VK API profile, err := getUserProfileFromVkApiByUserPhone(user.Phone) if err != nil { return nil, errors.New("error fetching user profile") } user.Profile = profile users = append(users, user) } if err = rows.Err(); err != nil { return nil, errors.New("error fetching user list") } }
-- list books sorted by id, -- but swap lines 2 and 3 in the output: -- 1 Master and Margarita 100 -- 3 The Golden Calf 50 -- 2 The Twelve Chairs 200 -- 4 Eugene Onegin 250 -- 5 Belya's Stories 90 -- 6 The Three Musketeers 60