Skip to content

Filtering data in profile-related routes

tecc requested to merge change/api-performance-improvements into main

Currently, profile-related routes send a lot of data - most of it unnecessary in many cases. Reducing the amount of data sent for each request could tremendously improve API and website performance for users and external applications.

This PR provides an implementation of filtering data in profile requests, which is opt-in only. So far, only the cards are filtered (the remaining information is arguably small enough to ignore).

How to specify a filter

The properties that the server should include in the response body are specified using query parameters like so:

  • The props parameter defines what should be included by default. The value is parsed as described in the Filter value section.
  • To specify locale-specific filters, lprops is used - either using the syntax lprops[<locale>] or lprops.<locale> (substituting <locale> for the locale code of the locale you wish to specify a filter for - it must be lowercase, importantly). The value is parsed precisely like the props parameter.

If props is unspecified, it effectively defaults to all.

Filter value

A filter essentially consists of several keys that can be enabled or disabled, as well as a default value.

The rules for parsing the filters as specified in the query are as follows:

  • If it is an array (specified qs-style or through using multiple instances of the same key), each element is interpreted as a key to be enabled.
  • If it is an object (specified qs-style), it is directly passed to the resulting instance. This is not recommended.
  • If it is a string, it is parsed using the following rules:
    • If it is equal to none, the card object will not be included. This is optimal for filtering out all unnecessary data.
    • If it is equal to empty, the card object will be included but it will be empty. This is primarily directed at listing each locale the requested user has a card in, without getting all of the data for each locale.
    • If it is equal to all, the card object will be included and it will include all properties.
    • If none of the previous are true, the string is treated as a comma-separated list of keys.

Table of keys

Key Property in card object Description
opinions opinions Opinions.
names names Names.
pronouns pronouns Pronouns.
age age, birthday Age-related properties.
links links, linksMetadata, verifiedLinks Links and some meta information about them.
flags flags, customFlags Flags.
words words Words.
timezone timezone Timezone.
team teamName, footerName, footerAreas Team.
credentials credentials, credentialsLevel, credentialsName Credentials. This is an obscure property though.
card_image card, cardDark Card images.
circle circle Circle.
sensitive sensitive Warnings for users viewing the profile.

Notes

  • Currently, only the get profile route supports filtering. The save and delete routes do not.

TODO

  • Make pages using the profile API use filters.
Edited by tecc

Merge request reports

Loading