Commit 99eefcb54d0f467a96629ef63caaf3cceda18eb6

Authored by Dmitriy Zaporozhets
1 parent ffa46e02

Invalidate events cache when project was moved

app/models/project.rb
... ... @@ -423,6 +423,7 @@ class Project < ActiveRecord::Base
423 423 gitlab_shell.rm_satellites(old_path_with_namespace)
424 424 ensure_satellite_exists
425 425 send_move_instructions
  426 + reset_events_cache
426 427 rescue
427 428 # Returning false does not rollback after_* transaction but gives
428 429 # us information about failing some of tasks
... ... @@ -434,4 +435,19 @@ class Project < ActiveRecord::Base
434 435 raise Exception.new('repository cannot be renamed')
435 436 end
436 437 end
  438 +
  439 + # Reset events cache related to this project
  440 + #
  441 + # Since we do cache @event we need to reset cache in special cases:
  442 + # * when project was moved
  443 + # * when project was renamed
  444 + # Events cache stored like events/23-20130109142513.
  445 + # The cache key includes updated_at timestamp.
  446 + # Thus it will automatically generate a new fragment
  447 + # when the event is updated because the key changes.
  448 + def reset_events_cache
  449 + Event.where(project_id: self.id).
  450 + order('id DESC').limit(100).
  451 + update_all(updated_at: Time.now)
  452 + end
437 453 end
... ...
app/services/project_transfer_service.rb
... ... @@ -32,6 +32,9 @@ class ProjectTransferService
32 32 # create satellite repo
33 33 project.ensure_satellite_exists
34 34  
  35 + # clear project cached events
  36 + project.reset_events_cache
  37 +
35 38 true
36 39 end
37 40 end
... ...