summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-26 19:33:18 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-26 19:33:18 +0300
commitcb0d63b9e3fa464ae8c0cd9cf7bdb8d080a7e02f (patch)
tree7bbd00eabc693e0b3ca0ae6157fea514922ab79c
parent8734a9cde81a757ab4f744db0944bf69ef927a96 (diff)
parent16eea49277e736c53078ec1e7b5005ac7a26a112 (diff)
downloadgitlab-ce-cb0d63b9e3fa464ae8c0cd9cf7bdb8d080a7e02f.tar.gz
Merge pull request #7319 from jvanbaarsen/small-eventcache-refactoring
Moved some behaviour to one place
-rw-r--r--app/models/event.rb6
-rw-r--r--app/models/issue.rb4
-rw-r--r--app/models/merge_request.rb4
-rw-r--r--app/models/note.rb4
4 files changed, 9 insertions, 9 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 8681c2e4d90..9e296c00281 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -70,6 +70,12 @@ class Event < ActiveRecord::Base
author_id: user.id
)
end
+
+ def reset_event_cache_for(target)
+ Event.where(target_id: target.id, target_type: target.class.to_s).
+ order('id DESC').limit(100).
+ update_all(updated_at: Time.now)
+ end
end
def proper?
diff --git a/app/models/issue.rb b/app/models/issue.rb
index a116a9354cb..b5a72d535d9 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -67,8 +67,6 @@ class Issue < ActiveRecord::Base
# Thus it will automatically generate a new fragment
# when the event is updated because the key changes.
def reset_events_cache
- Event.where(target_id: self.id, target_type: 'Issue').
- order('id DESC').limit(100).
- update_all(updated_at: Time.now)
+ Event.reset_event_cache_for(self)
end
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 28486fb41c6..686add63bbf 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -287,9 +287,7 @@ class MergeRequest < ActiveRecord::Base
# Thus it will automatically generate a new fragment
# when the event is updated because the key changes.
def reset_events_cache
- Event.where(target_id: self.id, target_type: 'MergeRequest').
- order('id DESC').limit(100).
- update_all(updated_at: Time.now)
+ Event.reset_event_cache_for(self)
end
def merge_commit_message
diff --git a/app/models/note.rb b/app/models/note.rb
index ed4829b2b39..7ff6444cc9b 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -327,9 +327,7 @@ class Note < ActiveRecord::Base
# Thus it will automatically generate a new fragment
# when the event is updated because the key changes.
def reset_events_cache
- Event.where(target_id: self.id, target_type: 'Note').
- order('id DESC').limit(100).
- update_all(updated_at: Time.now)
+ Event.reset_event_cache_for(self)
end
def set_references