diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-12 18:29:41 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-12 18:29:41 +0000 |
commit | dc28ada00673a5d41a2ad36af824d563276ecc0a (patch) | |
tree | 83529071143cd1f951ca06541632c703b0a03be9 /lib | |
parent | 49a9de110e4d2a70d006759529822b3823b63f96 (diff) | |
parent | 428c38a2b19866956ab6af61fbaa121b3bb1584d (diff) | |
download | gitlab-ce-dc28ada00673a5d41a2ad36af824d563276ecc0a.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 |