Skip to content

N+1 specs: prefer ignore cache to extra request

Jessie Young requested to merge jy-n-plus-one-docs into master

What does this MR do and why?

  • This MR adds documentation suggesting we use :use_sql_query_cache and skip_cached: false for N+1 specs rather than warming the cache via an extra request.
  • It also updates 2 specs using this style to illustrate the recommendation.
  • As I was working on a recent MR, I saw that many of our N+1 specs include 3 requests: 1 to warm cache, 2 to set control, 3 (with extra data) to test for N+1.
  • This approach is not documented anywhere. One example of where a 3rd request was added to make an N+1 test more accurate is here: !65602 (diffs, comment 620111660)
  • Rather than making this extra request to prevent a "false positive" where the control requests appears to have more SQL queries because it is using a cold cache, it seems more efficient to make 2 requests but ignore the cache count.
  • Ignoring cache makes sense anyway because cached queries are considered bad anyway: aa1d1848
  • This came up when I was working on: !98694 (diffs, comment 1153539282)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

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.

Merge request reports

Loading