Skip to content

Preload `avatar_url` for CompareController

What does this MR do and why?

Contributes to #363879 (closed)

Problem

We load all avatars of forked projects and that causes a performance problem.

Screenshot_2022-05-31_at_17.57.42

(source https://gitlab.com/gitlab-org/gitlab/-/compare)

Solution

By default we use batch loading for avatars, but in this case we want to avoid that. I call avatar_url method early to change the order of the batch load and fix the unoptimized query that fetches all avatars of project's forks.

👉 More details in the comment

Screenshots or screen recordings

Before After
Screenshot_2022-06-02_at_12.14.04 Screenshot_2022-06-02_at_12.13.31

Explanation

The query before the fix contains upload paths to original project (id: 4) and forked project (id: 64). For projects with many forks the query will have uploads paths of all of them in the WHERE. But we need the avatar of the original project only and we don't display avatars of forked projects.

The query after the fix correctly fetches only paths of the original project.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports

Loading