Skip to content

Commit

Permalink
feat(step): cache Step#service_result
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed May 24, 2024
1 parent 66cdf2a commit 2fd0cd9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,17 @@ Resolved by [b8285e3](/~https://github.com/marian13/convenient_service/commit/b828
That is not intuitive.

---

### Consider to replace `CachesReturnValue`

| Priority | Complexity | Status | Tags |
| - | - | - | - |
| Medium | Moderate | TODO | performance-optimization, CachesReturnValue |

Services and steps are caching their results utilizing the `CachesReturnValue` plugin.

Although it is very flexible and easy to reuse from the maintenance point of view, that is not the best option from the performance point of view.

In case it starts to cause any visible performance penalty, it can be refactored using regular `||=` or `if defined?`.

---
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def reassignment(name)
# NOTE: `service_result` returns a foreign result that is later converted to own result by `HasResult` middleware.
#
def service_result
service.klass.result(**input_values)
@service_result ||= service.klass.result(**input_values)
end

##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ def result
.with_arguments(**step.input_values)
.and_return_its_value
end

specify do
expect { step.service_result }.to cache_its_value
end
end
end

Expand Down

0 comments on commit 2fd0cd9

Please sign in to comment.