Skip to content

Fix an N+1 in avatar URLs

Sean McGivern requested to merge fix-avatars-n-plus-one into master

What does this MR do?

Currently, we run a query to the uploads table for each user on a page, if that user has uploaded an avatar.

This replaces those with one query.

Are there points in the code the reviewer needs to double check?

Yes, this is better than it was, but still not ideal. If an Avatarable's avatar upload changes during the context of a BatchLoader's cache lifetime, we have to expire that manually.

We also construct a dummy AR model to resolve the cached value.

Why was this MR needed?

N+1s are bad?

Does this MR meet the acceptance criteria?

  • Changelog entry added, if necessary
  • Tests added for this feature/bug
  • Review
    • Has been reviewed by Backend

What are the relevant issue numbers?

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/43114.

Edited by Sean McGivern

Merge request reports