# Changes to the user card data source

**URL:** https://meta.discourse.org/t/changes-to-the-user-card-data-source/139951
**Category:** Development
**Tags:** user-card, dev-news
**Created:** [January 28, 2020, 3:57pm UTC](https://meta.discourse.org/t/changes-to-the-user-card-data-source/139951 "2020-01-28T15:57:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 28, 2020, 3:57pm UTC](https://meta.discourse.org/t/changes-to-the-user-card-data-source/139951/1 "2020-01-28T15:57:48Z")

</div>

At the moment, when you click a user card, we load `/u/david.json`, which is exactly the same endpoint as my full profile. This is a little wasteful, since the user card doesn’t even use most of the data!

Therefore, we will be switching the user card to use a new route `/u/david/card.json`. This contains just enough information to render the card. In my testing, this makes user cards 2-3 times faster than before!

At the moment this change is behind a hidden site setting. To try it out, head to your rails console and run

```plaintext
SiteSetting.enable_new_user_card_route = true

```

In the next few weeks, this will be enabled by default, and the site setting will be removed. This is enabled right now on Meta.

### Great! What do I need to do?

If you’re a user or a forum admin, nothing! You should see improved performance on user cards very soon!

If you’re a plugin developer, you may need to make a few tweaks to support the new route.

### I use custom fields in my plugin, and render them on the user card

No problem, custom fields will continue working in exactly the same way

### I add data to the user serializer, and use it in the full user profile

Fine, the user profile will continue to use the old endpoint, and any existing `add_to_serializer` calls will continue to work

### I add data to the user serializer, and use it on the user card

Ok, you will need to do a little work. Previously we just had a structure like

```ruby
class UserSerializer < BasicUserSerializer

```

Now we have a structure like

```ruby
class UserCardSerializer < BasicUserSerializer
# and
class UserSerializer < UserCardSerializer

```

If you want something to be included in the card endpoint, you need to add it to the `UserCardSerializer`. For example, if you have code like this:

```ruby
add_to_serializer(:user, :favourite_forum_software) do
  "discourse"
end

```

You need to change it to

```ruby
add_to_serializer(:user_card, :favourite_forum_software) do
  "discourse"
end

```

The `UserSerializer` will automatically include anything in the `UserCardSerializer` so you can make this change straight away and it will work on tests-passed (even with the hidden site setting disabled).

To maintain compatibility with stable/beta, add a check for `UserCardSerializer` like this:

```ruby
# TODO: Remove switch once Discourse 2.4 stable is released
serializer = (defined? UserCardSerializer) ? :user_card : :user 
add_to_serializer(serializer, :favourite_forum_software) do
  "discourse"
end

```

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [January 29, 2020, 10:05am UTC](https://meta.discourse.org/t/changes-to-the-user-card-data-source/139951/2 "2020-01-29T10:05:45Z")

</div>

Great stuff @david. Really excited to see this one. I agree a 100% to the fact that a new serializer was needed to user cards.

I think this change also lays the ground for displaying user cards on the `/u` route.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 29, 2020, 12:20pm UTC](https://meta.discourse.org/t/changes-to-the-user-card-data-source/139951/3 "2020-01-29T12:20:00Z")

</div>

> [@fzngagan](#):
>
> I think this change also lays the ground for displaying user cards on the `/u` route.

It does indeed! Watch this space 👀

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [April 17, 2020, 8:43am UTC](https://meta.discourse.org/t/changes-to-the-user-card-data-source/139951/4 "2020-04-17T08:43:44Z")

</div>

> [@david](#):
>
> In the next few weeks, this will be enabled by default, and the site setting will be removed.

This is now the new default, and the setting has been removed

[https://github.com/discourse/discourse/commit/576872a2d93ce8546c5fded6d9edf5344c9bb4fe](https://github.com/discourse/discourse/commit/576872a2d93ce8546c5fded6d9edf5344c9bb4fe)
