Skip to content

Investigate less conservative approach to Gitlab/StrongMemoizeAttr cop with `strong_memoize_attr`

The following discussion from !102915 (merged) should be addressed:

  • @splattael started a discussion: (+1 comment)

    Question (non-blocking) This example suggests that we actually could strong_memoize_attr as well 🤷

    Do we have cases in our codebase where strong_memoize is not the entire body and strong_memoize_attr cannot be used? 🤔

    If fixing these cases is too hard, it's fine to not autocorrect them I think.

This example suggests that we actually could strong_memoize_attr as well 🤷

The problem is that anything that is outside the body of the strong_memoize() block will be executed regardless of whether the result was already memoized. When using strong_memoize_attr(), everything inside the method is memoized and only executed once. We don't know what the code outside strong_memoize() does, so I took the conservative approach of leaving it alone.

Do we have cases in our codebase where strong_memoize is not the entire body and strong_memoize_attr cannot be used? 🤔

I do recall seeing at least one instance of code outside the strong_memoize() block, but I don't remember whether it could have been safely moved inside strong_memoize(). It probably could have. Perhaps this should be another Rubocop?