Skip to content

Ensure that we only request blobs in one batch

What does this MR do?

Blob.lazy adds a blob to a batch to load at a later point, using the BatchLoader library. Whenever any lazy blob's attributes are accessed, all lazy blobs requested to that point will be loaded.

BatchLoader, the library we use for this, should only request items in a batch once. That is, if we have these batches:

  1. a, b, c
  2. d, e, f

Then a, b, and c should only be requested in the first batch. But if you modify the list of items in the batch, then the second batch will request a, b, c, d, e, f, which is almost certainly not what we want!

https://github.com/exAspArk/batch-loader/issues/44 is the upstream issue for this, but we can also solve this in our application by not modifying the arguments we're using inside a BatchLoader batch.

I tested this in production. Before, a request to https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21767/discussions.json took ~45s. After, it took ~32s. https://gitlab.com/gitlab-org/gitlab-ce/issues/58297 will probably make a much bigger difference here!

Before, Banzai::ObjectRenderer#post_process_documents took 24s. After, it took 9s.

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

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

Merge request reports