Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to request partial accounts in grouped notifications API #31299

Merged

Conversation

ClearlyClaire
Copy link
Contributor

@ClearlyClaire ClearlyClaire commented Aug 5, 2024

This allows clients to request trimmed-down versions of accounts in the grouped notifications API to cut down on payload side and server CPU time.

To do this, it introduces a new expand_accounts parameters that currently has two possible values: full (default, output full accounts in all cases) and partial_avatars which moves some of the accounts to partial_accounts with a trimmed-down version.

The fields for trimmed-down accounts are:

  • the fields required for immediate display in our current web user interface: id, acct, avatar and avatar_static
  • a few other cheap fields for future-proofing the API and potentially be useful to other clients: locked, bot, url

Example

GET /api/v2_alpha/notifications?expand_accounts=partial_avatars
Response
{
  "accounts": [
    {
      "id": "112909520826355962",
      "username": "renna_lockman409",
      "acct": "renna_lockman409",
      "display_name": "",
      "locked": false,
      "bot": false,
      "discoverable": true,
      "indexable": false,
      "group": false,
      "created_at": "2024-08-05T00:00:00.000Z",
      "note": "<p>hi i boost things!</p>",
      "url": "https://cb6e6126.ngrok.io/@renna_lockman409",
      "uri": "https://cb6e6126.ngrok.io/users/renna_lockman409",
      "avatar": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "avatar_static": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "header": "https://cb6e6126.ngrok.io/headers/original/missing.png",
      "header_static": "https://cb6e6126.ngrok.io/headers/original/missing.png",
      "followers_count": 0,
      "following_count": 0,
      "statuses_count": 1,
      "last_status_at": "2024-08-05",
      "hide_collections": null,
      "noindex": false,
      "emojis": [],
      "roles": [],
      "fields": []
    },
    {
      "id": "112909520799194838",
      "username": "sandy399",
      "acct": "sandy399",
      "display_name": "",
      "locked": false,
      "bot": false,
      "discoverable": true,
      "indexable": false,
      "group": false,
      "created_at": "2024-08-05T00:00:00.000Z",
      "note": "<p>hi i boost things!</p>",
      "url": "https://cb6e6126.ngrok.io/@sandy399",
      "uri": "https://cb6e6126.ngrok.io/users/sandy399",
      "avatar": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "avatar_static": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "header": "https://cb6e6126.ngrok.io/headers/original/missing.png",
      "header_static": "https://cb6e6126.ngrok.io/headers/original/missing.png",
      "followers_count": 0,
      "following_count": 0,
      "statuses_count": 1,
      "last_status_at": "2024-08-05",
      "hide_collections": null,
      "noindex": false,
      "emojis": [],
      "roles": [],
      "fields": []
    },
    {
      "id": "112909520772114535",
      "username": "mickey389",
      "acct": "mickey389",
      "display_name": "",
      "locked": false,
      "bot": false,
      "discoverable": true,
      "indexable": false,
      "group": false,
      "created_at": "2024-08-05T00:00:00.000Z",
      "note": "<p>hi i boost things!</p>",
      "url": "https://cb6e6126.ngrok.io/@mickey389",
      "uri": "https://cb6e6126.ngrok.io/users/mickey389",
      "avatar": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "avatar_static": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "header": "https://cb6e6126.ngrok.io/headers/original/missing.png",
      "header_static": "https://cb6e6126.ngrok.io/headers/original/missing.png",
      "followers_count": 0,
      "following_count": 0,
      "statuses_count": 1,
      "last_status_at": "2024-08-05",
      "hide_collections": null,
      "noindex": false,
      "emojis": [],
      "roles": [],
      "fields": []
    }
  ],
  "partial_accounts": [
    {
      "id": 112909520825810295,
      "acct": "tonisha408",
      "locked": false,
      "bot": false,
      "url": "https://cb6e6126.ngrok.io/@tonisha408",
      "avatar": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "avatar_static": "https://cb6e6126.ngrok.io/avatars/original/missing.png"
    },
    {
      "id": 112909520825346274,
      "acct": "frank407",
      "locked": false,
      "bot": false,
      "url": "https://cb6e6126.ngrok.io/@frank407",
      "avatar": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
      "avatar_static": "https://cb6e6126.ngrok.io/avatars/original/missing.png"
    },
    
  ],
  "statuses": [
    {
      "id": "112909520820351365",
      "created_at": "2024-08-05T12:56:01.345Z",
      "in_reply_to_id": null,
      "in_reply_to_account_id": null,
      "sensitive": false,
      "spoiler_text": "",
      "visibility": "public",
      "language": "en",
      "uri": "https://cb6e6126.ngrok.io/users/alice/statuses/112909520820351365",
      "url": "https://cb6e6126.ngrok.io/@alice/112909520820351365",
      "replies_count": 0,
      "reblogs_count": 10,
      "favourites_count": 0,
      "edited_at": null,
      "favourited": false,
      "reblogged": false,
      "muted": false,
      "bookmarked": false,
      "pinned": false,
      "content": "<p>Hello world!</p>",
      "filtered": [],
      "reblog": null,
      "application": null,
      "account": {
        "id": "112909519581744667",
        "username": "alice",
        "acct": "alice",
        "display_name": "",
        "locked": false,
        "bot": false,
        "discoverable": true,
        "indexable": false,
        "group": false,
        "created_at": "2024-08-05T00:00:00.000Z",
        "note": "<p>hello i&#39;m a test user with <a href=\"https://cb6e6126.ngrok.io/tags/hashtags\" class=\"mention hashtag\" rel=\"tag\">#<span>hashtags</span></a></p>",
        "url": "https://cb6e6126.ngrok.io/@alice",
        "uri": "https://cb6e6126.ngrok.io/users/alice",
        "avatar": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
        "avatar_static": "https://cb6e6126.ngrok.io/avatars/original/missing.png",
        "header": "https://cb6e6126.ngrok.io/headers/original/missing.png",
        "header_static": "https://cb6e6126.ngrok.io/headers/original/missing.png",
        "followers_count": 0,
        "following_count": 0,
        "statuses_count": 41,
        "last_status_at": "2024-08-05",
        "hide_collections": null,
        "noindex": false,
        "emojis": [],
        "roles": [],
        "fields": []
      },
      "media_attachments": [],
      "mentions": [],
      "tags": [],
      "emojis": [],
      "card": null,
      "poll": null
    },
    
  ],
  "notification_groups": [
    {
      "group_key": "reblog-112909520820351365-478572",
      "notifications_count": 10,
      "type": "reblog",
      "most_recent_notification_id": 401,
      "page_min_id": "392",
      "page_max_id": "401",
      "latest_page_notification_at": "2024-08-05T12:56:01.758Z",
      "sample_account_ids": [
        "112909520826355962",
        "112909520825810295",
        "112909520825346274",
        "112909520824837350",
        "112909520824425144",
        "112909520823924966",
        "112909520823464479",
        "112909520822940951"
      ],
      "status_id": "112909520820351365"
    },
    {
      "group_key": "reblog-112909520793485892-478572",
      "notifications_count": 10,
      "type": "reblog",
      "most_recent_notification_id": 391,
      "page_min_id": "382",
      "page_max_id": "391",
      "latest_page_notification_at": "2024-08-05T12:56:01.342Z",
      "sample_account_ids": [
        "112909520799194838",
        "112909520798717928",
        "112909520798230763",
        "112909520797793509",
        "112909520797362864",
        "112909520796860342",
        "112909520796411691",
        "112909520795973102"
      ],
      "status_id": "112909520793485892"
    },
    {
      "group_key": "reblog-112909520766941880-478572",
      "notifications_count": 10,
      "type": "reblog",
      "most_recent_notification_id": 381,
      "page_min_id": "381",
      "page_max_id": "381",
      "latest_page_notification_at": "2024-08-05T12:56:00.932Z",
      "sample_account_ids": [
        "112909520772114535",
        "112909520771628751",
        "112909520771222009",
        "112909520770788459",
        "112909520770387469",
        "112909520769908851",
        "112909520769545628",
        "112909520769116350"
      ],
      "status_id": "112909520766941880"
    }
  ]
}

Benchmark

I did a small benchmark of a manufactured scenario of 20×(1 reblog + 1 like) notification from the same set of 10 (fairly simple, with no account fields and a short bio) accounts.

expand_accounts=full takes around 385ms and returns a 334kb payload (before compression)

expand_accounts=partial_avatars takes around 203ms and returns a 186kb payload (before compression)

@ClearlyClaire ClearlyClaire force-pushed the features/grouped-notifications-api-partial-accounts branch 2 times, most recently from 07d49ff to a08ff5f Compare August 5, 2024 14:22
@ClearlyClaire ClearlyClaire force-pushed the features/grouped-notifications-api-partial-accounts branch from a08ff5f to 0eb9782 Compare August 5, 2024 15:52
@ClearlyClaire ClearlyClaire added the api REST API, Streaming API, Web Push API label Aug 6, 2024
@ClearlyClaire ClearlyClaire marked this pull request as ready for review August 6, 2024 07:42
@ClearlyClaire ClearlyClaire requested a review from a team August 6, 2024 07:50
@ClearlyClaire ClearlyClaire force-pushed the features/grouped-notifications-api-partial-accounts branch from baf60a9 to 76bd393 Compare August 6, 2024 09:41
@ClearlyClaire ClearlyClaire added this pull request to the merge queue Aug 6, 2024
Merged via the queue into main with commit 438dac9 Aug 6, 2024
29 checks passed
@ClearlyClaire ClearlyClaire deleted the features/grouped-notifications-api-partial-accounts branch August 6, 2024 12:19
justinwritescode pushed a commit to justinwritescode/mastodon that referenced this pull request Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api REST API, Streaming API, Web Push API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants