diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-12 18:29:41 +0000 |
---|---|---|
committer | Luke Bennett <lbennett@gitlab.com> | 2017-12-13 14:22:22 +0000 |
commit | 54f008126d83af1869572565336e01d3953b2b91 (patch) | |
tree | e88277096c44c04c063c7b1c6341d6420f31142b /lib | |
parent | 81038fbaf4b6267c87450fbaf04df2b4e4bbbe90 (diff) | |
download | gitlab-ce-54f008126d83af1869572565336e01d3953b2b91.tar.gz |
Merge branch 'zj-memoization-mr-commits' into 'master'
Use memoization for commits on diffs
See merge request gitlab-org/gitlab-ce!15857
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/conflict/file_collection.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/utils/strong_memoize.rb | 20 |
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/gitlab/conflict/file_collection.rb b/lib/gitlab/conflict/file_collection.rb index fb28e80ff73..b9099ce256a 100644 --- a/lib/gitlab/conflict/file_collection.rb +++ b/lib/gitlab/conflict/file_collection.rb @@ -19,6 +19,8 @@ module Gitlab commit_message: commit_message || default_commit_message } resolver.resolve_conflicts(user, files, args) + ensure + @merge_request.clear_memoized_shas end def files diff --git a/lib/gitlab/utils/strong_memoize.rb b/lib/gitlab/utils/strong_memoize.rb index a2ac9285b56..fe091f4611b 100644 --- a/lib/gitlab/utils/strong_memoize.rb +++ b/lib/gitlab/utils/strong_memoize.rb @@ -11,6 +11,8 @@ module Gitlab # # We could write it like: # + # include Gitlab::Utils::StrongMemoize + # # def trigger_from_token # strong_memoize(:trigger) do # Ci::Trigger.find_by_token(params[:token].to_s) @@ -18,14 +20,22 @@ module Gitlab # end # def strong_memoize(name) - ivar_name = "@#{name}" - - if instance_variable_defined?(ivar_name) - instance_variable_get(ivar_name) + if instance_variable_defined?(ivar(name)) + instance_variable_get(ivar(name)) else - instance_variable_set(ivar_name, yield) + instance_variable_set(ivar(name), yield) end end + + def clear_memoization(name) + remove_instance_variable(ivar(name)) if instance_variable_defined?(ivar(name)) + end + + private + + def ivar(name) + "@#{name}" + end end end end |