Flagsmith / Flagsmith/flagsmith

Optimise FE to remove N+1 calls to get project environments

Open
#7,949 2 comments 0 reactions 1 assignee Claimed by @talissoncosta View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

Currently when landing on https://app.flagsmith.com/organisation/:organisationId/projects, the FE iterates over all the projects and requests the environments for each one. For organisations with large numbers of projects this causes a performance overhead at the very least, and rate-limiting at the worst.

The FE should not need to get the environments at this point in the load of the dashboard. The reason that it retrieves them is to know where to route the user to when selecting a project since the next URL is built as https://app.flagsmith.com/project/:projectId/environment/:environmentKey/features (by accessing `project.environments[0].api_key`.

Some possible solutions to this issue:

1. The API returns an `environments` list in each Project object returned on `/api/v1/projects`. The `environments` list could include:
a. The whole environment object
b. A summary object including the `id`, `api_key` and `name`
c. Just a list of strings giving the `api_key` attributes of the environments
2. The FE retrieves the environments when the user selects a project and then routes the user accordingly
3. The BE adds functionality to add a 'default_environment' attribute to the project which the FE can route to

Option (1) would likely be the easiest as it means no refactor on the FE. Option (3) is perhaps the cleanest, but opens the question about whether it would be better to store this preference per user, or maybe use something like `last_environment_visited`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.